mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:18:13 +00:00
ad6122810a
Golem config expects RunTimeRaw metric (as we want to see not runs per second but a more meaningful benchmark, i.e. how much transferring 1KB of data takes) => Golem cannot just display it in different form, we have to make the benchmark report it also as RunTimeRaw. => This CL should fix the golem benchmarks. Change-Id: I91301930941986771eb0725fd0d85424bb07dc3a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372640 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
129 lines
3.9 KiB
Dart
129 lines
3.9 KiB
Dart
// Copyright (c) 2024, 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:js_interop';
|
|
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
|
|
|
void main(List<String> args) {
|
|
final smallDartString = 'a' * 10;
|
|
final mediumDartString = 'a' * 1024;
|
|
final largeDartString = 'a' * 1024 * 1024;
|
|
|
|
final smallJsString = smallDartString.toJS;
|
|
final mediumJsString = mediumDartString.toJS;
|
|
final largeJsString = largeDartString.toJS;
|
|
|
|
final smallDartBytes = utf8.encode(smallDartString);
|
|
final mediumDartBytes = utf8.encode(mediumDartString);
|
|
final largeDartBytes = utf8.encode(largeDartString);
|
|
|
|
final smallJsBytes = smallDartBytes.toJS;
|
|
final mediumJsBytes = mediumDartBytes.toJS;
|
|
final largeJsBytes = largeDartBytes.toJS;
|
|
|
|
WasmDataTransferFromBrowserString(smallJsString, '10').report();
|
|
WasmDataTransferFromBrowserBytes(smallJsBytes, '10').report();
|
|
WasmDataTransferToBrowserString(smallDartString, '10').report();
|
|
WasmDataTransferToBrowserBytes(smallDartBytes, '10').report();
|
|
|
|
WasmDataTransferFromBrowserString(mediumJsString, '1KB').report();
|
|
WasmDataTransferFromBrowserBytes(mediumJsBytes, '1KB').report();
|
|
WasmDataTransferToBrowserString(mediumDartString, '1KB').report();
|
|
WasmDataTransferToBrowserBytes(mediumDartBytes, '1KB').report();
|
|
|
|
WasmDataTransferFromBrowserString(largeJsString, '1MB').report();
|
|
WasmDataTransferFromBrowserBytes(largeJsBytes, '1MB').report();
|
|
WasmDataTransferToBrowserString(largeDartString, '1MB').report();
|
|
WasmDataTransferToBrowserBytes(largeDartBytes, '1MB').report();
|
|
}
|
|
|
|
class PrintEmitter implements ScoreEmitter {
|
|
const PrintEmitter();
|
|
|
|
@override
|
|
void emit(String testName, double value) {
|
|
print('$testName(RunTimeRaw): $value us.');
|
|
}
|
|
}
|
|
|
|
abstract class Benchmark extends BenchmarkBase {
|
|
Benchmark(super.name) : super(emitter: const PrintEmitter());
|
|
|
|
@override
|
|
void exercise() {
|
|
// To avoid using the super class's implementation which runs for 10
|
|
// iterations thereby making the measured time off by 10x.
|
|
run();
|
|
}
|
|
}
|
|
|
|
class WasmDataTransferFromBrowserString extends Benchmark {
|
|
final JSString jsonString;
|
|
|
|
WasmDataTransferFromBrowserString(this.jsonString, String subName)
|
|
: super('WasmDataTransfer.FromBrowserString.$subName');
|
|
|
|
@override
|
|
void run() {
|
|
// We don't expose a way to convert JS string to Dart string (as string
|
|
// implementation in Dart is implementation specific - we may even use JS
|
|
// strings).
|
|
//
|
|
// But currently we use internal one/two byte strings and using string
|
|
// interpolation forces transfer of string to be internal string.
|
|
//
|
|
// Though string interpolation also causes other work (it convers JS string
|
|
// to dart and then allocates new string for interpolation result)
|
|
use('a${jsonString.toDart}');
|
|
}
|
|
}
|
|
|
|
class WasmDataTransferFromBrowserBytes extends Benchmark {
|
|
final JSUint8Array bytes;
|
|
|
|
WasmDataTransferFromBrowserBytes(this.bytes, String subName)
|
|
: super('WasmDataTransfer.FromBrowserBytes.$subName');
|
|
|
|
@override
|
|
void run() {
|
|
use(Uint8List.fromList(bytes.toDart));
|
|
}
|
|
}
|
|
|
|
class WasmDataTransferToBrowserString extends Benchmark {
|
|
final String string;
|
|
|
|
WasmDataTransferToBrowserString(this.string, String subName)
|
|
: super('WasmDataTransfer.ToBrowserString.$subName');
|
|
|
|
@override
|
|
void run() {
|
|
use(string.toJS);
|
|
}
|
|
}
|
|
|
|
class WasmDataTransferToBrowserBytes extends Benchmark {
|
|
final Uint8List bytes;
|
|
|
|
WasmDataTransferToBrowserBytes(this.bytes, String subName)
|
|
: super('WasmDataTransfer.ToBrowserBytes.$subName');
|
|
|
|
@override
|
|
void run() {
|
|
use(bytes.toJS);
|
|
}
|
|
}
|
|
|
|
var globalSink;
|
|
void use<T>(T a) {
|
|
globalSink = a;
|
|
if (kFalse) print(globalSink);
|
|
}
|
|
|
|
final kTrue = int.parse('1') == 1;
|
|
final kFalse = !kTrue;
|