nandi/vflutter_ffipublic Fork 0
728acaab2594667f4998fc18812e7c1e2e4cc549
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

fractal_bench.dart · 54 lines · 1.8 KBDart Blame HistoryRaw
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 20h ago1// Headless benchmark: the same Mandelbrot frame rendered by V and by Dart.
2//
3// LD_LIBRARY_PATH=build dart example/lib/fractal_bench.dart
4//
5// Also checks the two implementations agree pixel-for-pixel, which is what
6// makes the timing comparison meaningful.
7import 'package:vflutter_ffi/vflutter_ffi.dart' as v;
8
9import 'mandelbrot_dart.dart';
10
11Future<void> main() async {
12 const view = v.FractalView(width: 800, height: 600, maxIter: 500);
13 final pixels = view.width * view.height;
14
15 // Warm both paths: first call pays for library load / JIT.
16 v.render(const v.FractalView(width: 64, height: 64, maxIter: 50));
17 renderDart(const v.FractalView(width: 64, height: 64, maxIter: 50));
18
19 final swV = Stopwatch()..start();
20 final fromV = v.render(view);
21 swV.stop();
22
23 final swP = Stopwatch()..start();
24 final fromParallel = await v.renderParallel(view, tiles: 4);
25 swP.stop();
26
27 final swD = Stopwatch()..start();
28 final fromDart = renderDart(view);
29 swD.stop();
30
31 print('${view.width}x${view.height}, maxIter ${view.maxIter} '
32 '($pixels px)\n');
33 print('V, one isolate ${swV.elapsedMilliseconds} ms');
34 print('V, 4 isolates ${swP.elapsedMilliseconds} ms');
35 print('Dart, one isolate ${swD.elapsedMilliseconds} ms');
36 print('speedup vs Dart '
37 '${(swD.elapsedMicroseconds / swV.elapsedMicroseconds).toStringAsFixed(2)}x '
38 'serial, '
39 '${(swD.elapsedMicroseconds / swP.elapsedMicroseconds).toStringAsFixed(2)}x '
40 'parallel');
41
42 print('\nagreement checks');
43 print(' V serial vs V parallel : ${_diff(fromV, fromParallel)} bytes differ');
44 print(' V serial vs Dart : ${_diff(fromV, fromDart)} bytes differ');
45}
46
47int _diff(List<int> a, List<int> b) {
48 if (a.length != b.length) return -1;
49 var n = 0;
50 for (var i = 0; i < a.length; i++) {
51 if (a[i] != b[i]) n++;
52 }
53 return n;
54}