mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 20:19:39 +00:00
[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:
parent
9eabbf1bc0
commit
455a105c42
|
@ -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();
|
||||
}
|
||||
}
|
14
benchmarks/EventLoopLatencyRegexp/dart/regexp_benchmark.dart
Normal file
14
benchmarks/EventLoopLatencyRegexp/dart/regexp_benchmark.dart
Normal 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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue