[benchmarks] Add IsolateFibonacci benchmark wrapper around existing test.

Change-Id: I66268cd24bcf55dd75baf7000948dcbe81928001
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209180
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2021-08-09 15:02:28 +00:00 committed by commit-bot@chromium.org
parent ae1e2bd3a6
commit 7c772a653b
4 changed files with 138 additions and 40 deletions

View file

@ -0,0 +1,66 @@
// 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:async';
import 'dart:io';
import 'dart:isolate';
import 'dart:math';
import 'package:expect/expect.dart';
// Implements recursive summation via tail calls:
// fib(n) => n <= 1 ? 1
// : fib(n-1) + fib(n-2);
Future fibonacciRecursive(List args) async {
final SendPort port = args[0];
final n = args[1];
if (n <= 1) {
port.send(1);
return;
}
final left = ReceivePort();
final right = ReceivePort();
await Future.wait([
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
]);
final results = await Future.wait([left.first, right.first]);
port.send(results[0] + results[1]);
}
Future<void> main() async {
final rpWarmup = ReceivePort();
final rpRun = ReceivePort();
final int nWarmup = 17; // enough runs to trigger optimized compilation
final int nWarmupFactorial = 2584;
// With --enable-isolate-groups runs for about 8 seconds.
// Should not be run witout --enable-isolate-groups as it would be too slow.
final int n = 21;
final int nFactorial = 17711;
final beforeRss = ProcessInfo.currentRss;
int maxRss = beforeRss;
final rssTimer = Timer.periodic(const Duration(milliseconds: 10), (_) {
maxRss = max(ProcessInfo.currentRss, maxRss);
});
final watch = Stopwatch();
watch.start();
// For the benefit of enable-isolate-groups configuration, warm up target
// isolate code by running couple iterations in the main isolate.
await Isolate.spawn(fibonacciRecursive, [rpWarmup.sendPort, nWarmup]);
Expect.equals(nWarmupFactorial, await rpWarmup.first);
final warmup = watch.elapsedMicroseconds;
await Isolate.spawn(fibonacciRecursive, [rpRun.sendPort, n]);
Expect.equals(nFactorial, await rpRun.first);
final done = watch.elapsedMicroseconds;
print('IsolateFibonacci_$n.Calculation(RunTimeRaw): ${done-warmup} us.');
print('IsolateFibonacci_$n.DeltaPeak(MemoryUse): ${maxRss-beforeRss}');
rssTimer.cancel();
}

View file

@ -0,0 +1,66 @@
// 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:async';
import 'dart:io';
import 'dart:isolate';
import 'dart:math';
import 'package:expect/expect.dart';
// Implements recursive summation via tail calls:
// fib(n) => n <= 1 ? 1
// : fib(n-1) + fib(n-2);
Future fibonacciRecursive(List args) async {
final SendPort port = args[0];
final n = args[1];
if (n <= 1) {
port.send(1);
return;
}
final left = ReceivePort();
final right = ReceivePort();
await Future.wait([
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
]);
final results = await Future.wait([left.first, right.first]);
port.send(results[0] + results[1]);
}
Future<void> main() async {
final rpWarmup = ReceivePort();
final rpRun = ReceivePort();
final int nWarmup = 17; // enough runs to trigger optimized compilation
final int nWarmupFactorial = 2584;
// With --enable-isolate-groups runs for about 8 seconds.
// Should not be run witout --enable-isolate-groups as it would be too slow.
final int n = 21;
final int nFactorial = 17711;
final beforeRss = ProcessInfo.currentRss;
int maxRss = beforeRss;
final rssTimer = Timer.periodic(const Duration(milliseconds: 10), (_) {
maxRss = max(ProcessInfo.currentRss, maxRss);
});
final watch = Stopwatch();
watch.start();
// For the benefit of enable-isolate-groups configuration, warm up target
// isolate code by running couple iterations in the main isolate.
await Isolate.spawn(fibonacciRecursive, [rpWarmup.sendPort, nWarmup]);
Expect.equals(nWarmupFactorial, await rpWarmup.first);
final warmup = watch.elapsedMicroseconds;
await Isolate.spawn(fibonacciRecursive, [rpRun.sendPort, n]);
Expect.equals(nFactorial, await rpRun.first);
final done = watch.elapsedMicroseconds;
print('IsolateFibonacci_$n.Calculation(RunTimeRaw): ${done-warmup} us.');
print('IsolateFibonacci_$n.DeltaPeak(MemoryUse): ${maxRss-beforeRss}');
rssTimer.cancel();
}

View file

@ -8,6 +8,9 @@ import 'dart:isolate';
import 'internal.dart';
export '../../../../../benchmarks/IsolateFibonacci/dart/IsolateFibonacci.dart'
show fibonacciRecursive;
final bool isDebugMode = Platform.script.path.contains('Debug');
final bool isSimulator = Platform.script.path.contains('SIM');
final bool isArtificialReloadMode = Platform.executableArguments.any((arg) => [
@ -44,26 +47,6 @@ Future sumRecursiveTailCall(List args) async {
}
}
// Implements recursive summation via tail calls:
// fib(n) => n <= 1 ? 1
// : fib(n-1) + fib(n-2);
Future fibonacciRecursive(List args) async {
final SendPort port = args[0];
final n = args[1];
if (n <= 1) {
port.send(1);
return;
}
final left = ReceivePort();
final right = ReceivePort();
await Future.wait([
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
]);
final results = await Future.wait([left.first, right.first]);
port.send(results[0] + results[1]);
}
enum Command { kRun, kRunAndClose, kClose }
abstract class RingElement {

View file

@ -10,6 +10,9 @@ import 'dart:isolate';
import 'internal.dart';
export '../../../../../benchmarks/IsolateFibonacci/dart2/IsolateFibonacci.dart'
show fibonacciRecursive;
final bool isDebugMode = Platform.script.path.contains('Debug');
final bool isSimulator = Platform.script.path.contains('SIM');
final bool isArtificialReloadMode = Platform.executableArguments.any((arg) => [
@ -46,26 +49,6 @@ Future sumRecursiveTailCall(List args) async {
}
}
// Implements recursive summation via tail calls:
// fib(n) => n <= 1 ? 1
// : fib(n-1) + fib(n-2);
Future fibonacciRecursive(List args) async {
final SendPort port = args[0];
final n = args[1];
if (n <= 1) {
port.send(1);
return;
}
final left = ReceivePort();
final right = ReceivePort();
await Future.wait([
Isolate.spawn(fibonacciRecursive, [left.sendPort, n - 1]),
Isolate.spawn(fibonacciRecursive, [right.sendPort, n - 2]),
]);
final results = await Future.wait([left.first, right.first]);
port.send(results[0] + results[1]);
}
enum Command { kRun, kRunAndClose, kClose }
abstract class RingElement {