runBenchmarkSuite function

List<BenchmarkResult> runBenchmarkSuite({
  1. int iterations = 10000,
})

Run the full benchmark suite. Returns all results.

Implementation

List<BenchmarkResult> runBenchmarkSuite({int iterations = 10000}) {
  return [
    benchmark('Cell read/write', () {
      final ctx = Context();
      final c = Source<int>(ctx, 0);
      c.value = 42;
      c.value;
    }, iterations: iterations),
    benchmark('Slot recompute', () {
      final ctx = Context();
      final a = Source<int>(ctx, 1);
      final b = Source<int>(ctx, 2);
      final sum = Slot<int>(ctx, (cx) => cx.get(a) + cx.get(b));
      a.value = 10;
      sum();
    }, iterations: iterations),
    benchmark('Computed equality guard (cache hit)', () {
      final ctx = Context();
      final src = Source<int>(ctx, 4);
      final parity =
          computed<String>(ctx, (cx) => cx.get(src).isEven ? 'even' : 'odd');
      src.value = 6; // still even — the guard suppresses
      parity();
    }, iterations: iterations),
    benchmark('batch coalesce (10 cells)', () {
      final ctx = Context();
      final cells = [for (var i = 0; i < 10; i++) Source<int>(ctx, i)];
      Effect(ctx, (cx) {
        for (final c in cells) {
          cx.get(c);
        }
        return null;
      });
      ctx.batch(() {
        for (var i = 0; i < 10; i++) {
          cells[i].value = i + 1;
        }
      });
    }, iterations: iterations),
    benchmark('SourceMap insert + read', () {
      final ctx = Context();
      final map = SourceMap<String, int>(ctx);
      for (var i = 0; i < 10; i++) {
        map.set('k$i', i);
      }
      map.read('k5');
    }, iterations: iterations),
    benchmark('TextCrdt insert 100 chars', () {
      final crdt = TextCrdt(1);
      for (var i = 0; i < 100; i++) {
        crdt.insert(i, 'a');
      }
    }, iterations: iterations ~/ 10),
    benchmark('SeqCrdt insert 100 elements', () {
      final seq = SeqCrdt<int, int>(1);
      for (var i = 0; i < 100; i++) {
        seq.insertBack(i, i, i);
      }
    }, iterations: iterations ~/ 10),
    benchmark('Position.compareTo ordering (300)', () {
      // #lzdartuint8list — isolates Position.compareTo on the SeqCrdt sort path.
      // The seq is built once (outside the timed body) so the measurement is the
      // fractional-index ordering, not the O(n²) insert scan.
      _seqForOrdering.order();
    }, iterations: iterations ~/ 10),
    benchmark('contentHash realistic text', () {
      // #lzdarthashint — FNV-1a content hash over a ~300-char normalized block.
      contentHash(
          'the quick brown fox jumps over the lazy dog '
          'while a pack of hounds gives chase through the glen; '
          'reactive signals propagate invalidation downstream '
          'and slots recompute only when their dependencies change.');
    }, iterations: iterations ~/ 2),
    benchmark('reconcileDiff 100-entry list', () {
      // #lzdartreconcileidx — keyed reconciliation of a 100-entry list with a
      // scrambled order (exercises the common-key index lookup). prior/target
      // are built once outside the timed body so only the reconciliation runs.
      reconcileDiff(_prior100, _target100);
    }, iterations: iterations ~/ 2),
  ];
}