Files
sdk/benchmarks/EventLoopLatencyJson350KB/dart/EventLoopLatencyJson350KB.dart
T
Robert Nystrom e4c8b49dcc Format benchmarks/.
Change-Id: I1362ada67a02b0ed352612fc29c727e94d8cd254
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394901
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2024-11-18 10:06:01 +00:00

37 lines
1.0 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:isolate';
import 'json_benchmark.dart';
import 'latency.dart';
Future<void> main() async {
// Start GC pressure from helper isolate.
final exitPort = ReceivePort();
final exitFuture = exitPort.first;
final isolate = await Isolate.spawn(run, null, onExit: exitPort.sendPort);
// Measure event loop latency.
const tickDuration = Duration(milliseconds: 1);
const numberOfTicks = 8 * 1000; // min 8 seconds.
final EventLoopLatencyStats stats = await measureEventLoopLatency(
tickDuration,
numberOfTicks,
);
// Kill isolate & wait until it's dead.
isolate.kill(priority: Isolate.immediate);
await exitFuture;
// Report event loop latency statistics.
stats.report('EventLoopLatencyJson350KB');
}
void run(dynamic msg) {
while (true) {
JsonRoundTripBenchmark().run();
}
}