nandi/frqpublic Fork 0
1d62d1a437b844c37e3e4d49efa7e255ef4deac7
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

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

Nim owns the screen, Dart owns the pixels 43a02c2 · on 1d62d1a437b844c37e3e4d49efa7e255ef4deac7 · nandi · yesterday
bench.dart · 48 lines · 1.5 KBDart Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/// What the boundary costs, measured rather than assumed.
///
/// The spike's architecture rebuilds the whole screen in Nim and ships it as
/// JSON on every event. That is the obvious objection to it, so this is the
/// number that answers the objection — or doesn't.
///
///   just nim-bench
import 'dart:convert';
import 'package:frq_core/frq_core.dart' as core;

void main() {
  core.resetUi();
  final json = jsonEncode({'id': 'noop'});
  print('tree size: ${core.render().toString().length} chars (as objects)');

  // The raw JSON, to say what actually crosses the wire.
  final bytes = utf8.encode(jsonEncode(_flatten(core.render())));
  print('tree bytes: ${bytes.length}');

  for (final n in [1000, 10000]) {
    var sw = Stopwatch()..start();
    for (var i = 0; i < n; i++) {
      core.render();
    }
    sw.stop();
    final perRender = sw.elapsedMicroseconds / n;
    print('render():   ${perRender.toStringAsFixed(1)}µs  '
        '(${(1000000 / perRender).round()}/s, '
        '${(perRender / 16666 * 100).toStringAsFixed(3)}% of a 60fps frame)');

    sw = Stopwatch()..start();
    for (var i = 0; i < n; i++) {
      core.dispatch('tls.toggle');
    }
    sw.stop();
    final perDispatch = sw.elapsedMicroseconds / n;
    print('dispatch(): ${perDispatch.toStringAsFixed(1)}µs  '
        '(${(1000000 / perDispatch).round()}/s)');
  }
  // ignore: unused_local_variable
  final _ = json;
}

Map<String, dynamic> _flatten(core.UiNode n) => {
      'tag': n.tag,
      'props': n.props,
      'children': n.children.map(_flatten).toList(),
    };