nandi/vflutter_ffipublic Fork 0
472eb493bac94bdcb79a38829ccca0c541256fef
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
Replace V with Nim 472eb49 nandithebull 8h ago1// Headless benchmark: the same Mandelbrot frame rendered by Nim and by Dart.
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago2//
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.
Replace V with Nim 472eb49 nandithebull 8h ago7import 'package:nimflutter_ffi/nimflutter_ffi.dart' as v;
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago8
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();
Replace V with Nim 472eb49 nandithebull 8h ago20 final fromNim = v.render(view);
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago21 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');
Replace V with Nim 472eb49 nandithebull 8h ago33 print('Nim, one isolate ${swV.elapsedMilliseconds} ms');
34 print('Nim, 4 isolates ${swP.elapsedMilliseconds} ms');
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago35 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');
Replace V with Nim 472eb49 nandithebull 8h ago43 print(' Nim serial vs Nim parallel : ${_diff(fromNim, fromParallel)} bytes differ');
44 print(' Nim serial vs Dart : ${_diff(fromNim, fromDart)} bytes differ');
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago45}
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}