[vm/benchmark] Introduce benchmarks that measures event loop latency for regexp processing.

This captures performance issues reported on https://github.com/flutter/flutter/issues/88063

Change-Id: Ie216808a02231be7915c60268718f3e0a0dc3c99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210282
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2021-08-16 18:41:49 +00:00 committed by commit-bot@chromium.org
parent 9eabbf1bc0
commit 455a105c42
4 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,33 @@
// Copyright (c) 2021, 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 'regexp_benchmark.dart';
import '../../EventLoopLatencyJson/dart/latency.dart';
main() async {
final exitPort = ReceivePort();
final exitFuture = exitPort.first;
final isolate = await Isolate.spawn(run, null, onExit: exitPort.sendPort);
// Measure event loop latency.
const tickDuration = const 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('EventLoopLatencyRegexp');
}
void run(dynamic msg) {
while (true) {
RegexpBenchmark().run();
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2021, 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:math';
import 'dart:convert';
class RegexpBenchmark {
void run() {
final re = RegExp(r'(x+)*y');
final s = 'x' * 26 + '';
re.allMatches(s).iterator.moveNext();
}
}

View file

@ -0,0 +1,35 @@
// 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.
// @dart=2.9
import 'dart:isolate';
import 'json_benchmark.dart';
import '../../EventLoopLatencyJson/dart2/latency.dart';
main() async {
final exitPort = ReceivePort();
final exitFuture = exitPort.first;
final isolate = await Isolate.spawn(run, null, onExit: exitPort.sendPort);
// Measure event loop latency.
const tickDuration = const 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('EventLoopLatencyRegexp');
}
void run(dynamic msg) {
while (true) {
RegexpBenchmark().run();
}
}

View file

@ -0,0 +1,16 @@
// Copyright (c) 2021, 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.
// @dart=2.9
import 'dart:math';
import 'dart:convert';
class RegexpBenchmark {
void run() {
final re = RegExp(r'(x+)*y');
final s = 'x' * 26 + '';
re.allMatches(s).iterator.moveNext();
}
}