Reformat benchmarks/ with 3.8 style.
Change-Id: Ied900f7d85addabc586823139aa78b879be035ea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425182 Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
This commit is contained in:
committed by
Commit Queue
parent
237ba8de01
commit
ff87171f6c
@@ -335,11 +335,10 @@ void main() {
|
||||
|
||||
// Warm up all benchmarks to ensure consistent behavior of shared code.
|
||||
benchmarks.forEach(
|
||||
(bm) =>
|
||||
bm()
|
||||
..setup()
|
||||
..run()
|
||||
..run(),
|
||||
(bm) => bm()
|
||||
..setup()
|
||||
..run()
|
||||
..run(),
|
||||
);
|
||||
|
||||
benchmarks.forEach((bm) => bm().report());
|
||||
|
||||
@@ -83,10 +83,9 @@ class BenchmarkAlternatingSizedAdd extends AsyncBenchmarkBase {
|
||||
@override
|
||||
Future<void> setup() async {
|
||||
_tempDir = Directory.systemTemp.createTempSync();
|
||||
_ioSink =
|
||||
File(
|
||||
_tempDir.uri.resolve('alternative-add-size').toFilePath(),
|
||||
).openWrite();
|
||||
_ioSink = File(
|
||||
_tempDir.uri.resolve('alternative-add-size').toFilePath(),
|
||||
).openWrite();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -54,8 +54,8 @@ class SendReceiveHelper {
|
||||
port = ReceivePort();
|
||||
inbox = StreamIterator<dynamic>(port);
|
||||
workerCompleted = Completer<bool>();
|
||||
workerExitedPort =
|
||||
ReceivePort()..listen((_) => workerCompleted.complete(true));
|
||||
workerExitedPort = ReceivePort()
|
||||
..listen((_) => workerCompleted.complete(true));
|
||||
worker = await Isolate.spawn(
|
||||
isolate,
|
||||
StartMessage(port.sendPort, useTransferable, size),
|
||||
|
||||
@@ -118,8 +118,9 @@ class BenchmarkConfig {
|
||||
}
|
||||
|
||||
Future<void> main() async {
|
||||
final jsonString =
|
||||
File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync();
|
||||
final jsonString = File(
|
||||
'benchmarks/IsolateJson/dart/sample.json',
|
||||
).readAsStringSync();
|
||||
final json250KB = utf8.encode(jsonString); // 294356 bytes
|
||||
final decoded = json.decode(utf8.decode(json250KB));
|
||||
final decoded1MB = <dynamic, dynamic>{
|
||||
|
||||
@@ -15,10 +15,10 @@ class SpawnLatency {
|
||||
final completerResult = Completer();
|
||||
final receivePort = ReceivePort()..listen(completerResult.complete);
|
||||
final isolateExitedCompleter = Completer<DateTime>();
|
||||
final onExitReceivePort =
|
||||
ReceivePort()..listen((_) {
|
||||
isolateExitedCompleter.complete(DateTime.now());
|
||||
});
|
||||
final onExitReceivePort = ReceivePort()
|
||||
..listen((_) {
|
||||
isolateExitedCompleter.complete(DateTime.now());
|
||||
});
|
||||
final beforeSpawn = DateTime.now();
|
||||
await Isolate.spawn(
|
||||
isolateCompiler,
|
||||
@@ -32,8 +32,9 @@ class SpawnLatency {
|
||||
receivePort.close();
|
||||
final DateTime isolateExited = await isolateExitedCompleter.future;
|
||||
result.timeToExitUs = isolateExited.difference(beforeSpawn).inMicroseconds;
|
||||
result.timeToIsolateSpawnUs =
|
||||
afterSpawn.difference(beforeSpawn).inMicroseconds;
|
||||
result.timeToIsolateSpawnUs = afterSpawn
|
||||
.difference(beforeSpawn)
|
||||
.inMicroseconds;
|
||||
onExitReceivePort.close();
|
||||
|
||||
return result;
|
||||
@@ -139,7 +140,8 @@ class AggregatedResultMessageLatency {
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => '''$toAfterIsolateSpawnUs
|
||||
String toString() =>
|
||||
'''$toAfterIsolateSpawnUs
|
||||
$toStartRunningCodeUs
|
||||
$toFinishRunningCodeUs
|
||||
$toExitUs''';
|
||||
@@ -164,10 +166,12 @@ Future<void> isolateCompiler(StartMessageLatency start) async {
|
||||
final timeFinishRunningCodeUs = DateTime.now();
|
||||
start.sendPort.send(
|
||||
ResultMessageLatency(
|
||||
timeToStartRunningCodeUs:
|
||||
timeRunningCodeUs.difference(start.spawned).inMicroseconds,
|
||||
timeToFinishRunningCodeUs:
|
||||
timeFinishRunningCodeUs.difference(start.spawned).inMicroseconds,
|
||||
timeToStartRunningCodeUs: timeRunningCodeUs
|
||||
.difference(start.spawned)
|
||||
.inMicroseconds,
|
||||
timeToFinishRunningCodeUs: timeFinishRunningCodeUs
|
||||
.difference(start.spawned)
|
||||
.inMicroseconds,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -224,14 +224,12 @@ void pollute() {
|
||||
final Map<String, Object> m2 = HashMap.of(m1);
|
||||
final Map<int, Object> m3 = Map.of({1: 66});
|
||||
final Map<int, Object> m4 = HashMap.of({1: 66});
|
||||
final Map<Object, Object> m5 =
|
||||
Map.identity()
|
||||
..[Thing()] = 1
|
||||
..[Thing()] = 2;
|
||||
final Map<Object, Object> m6 =
|
||||
HashMap.identity()
|
||||
..[Thing()] = 1
|
||||
..[Thing()] = 2;
|
||||
final Map<Object, Object> m5 = Map.identity()
|
||||
..[Thing()] = 1
|
||||
..[Thing()] = 2;
|
||||
final Map<Object, Object> m6 = HashMap.identity()
|
||||
..[Thing()] = 1
|
||||
..[Thing()] = 2;
|
||||
final Map<Object, Object> m7 = UnmodifiableMapView(m1);
|
||||
final Map<Object, Object> m8 = UnmodifiableMapView(m2);
|
||||
final Map<Object, Object> m9 = UnmodifiableMapView(m3);
|
||||
|
||||
@@ -13,40 +13,39 @@ import 'package:ffi/ffi.dart';
|
||||
|
||||
const maxSizeInBytes = 10 * 1024 * 1024;
|
||||
|
||||
final argParser =
|
||||
ArgParser()
|
||||
..addMultiOption(
|
||||
'length',
|
||||
abbr: 'l',
|
||||
help: 'Byte length to benchmark',
|
||||
valueHelp: 'INT',
|
||||
defaultsTo: const [],
|
||||
)
|
||||
..addFlag(
|
||||
'mebibytes-per-second',
|
||||
abbr: 'm',
|
||||
help: 'Show MiB/s',
|
||||
defaultsTo: false,
|
||||
)
|
||||
..addFlag(
|
||||
'nanoseconds-per-byte',
|
||||
abbr: 'n',
|
||||
help: 'Show ns/byte',
|
||||
defaultsTo: false,
|
||||
)
|
||||
..addFlag(
|
||||
'bytes-per-second',
|
||||
abbr: 'b',
|
||||
help: 'Show byte/s',
|
||||
defaultsTo: true,
|
||||
)
|
||||
..addFlag('verbose', abbr: 'v', help: 'Verbose output', defaultsTo: false)
|
||||
..addFlag(
|
||||
'aligned',
|
||||
abbr: 'a',
|
||||
help: 'Align results on initial numbers',
|
||||
defaultsTo: false,
|
||||
);
|
||||
final argParser = ArgParser()
|
||||
..addMultiOption(
|
||||
'length',
|
||||
abbr: 'l',
|
||||
help: 'Byte length to benchmark',
|
||||
valueHelp: 'INT',
|
||||
defaultsTo: const [],
|
||||
)
|
||||
..addFlag(
|
||||
'mebibytes-per-second',
|
||||
abbr: 'm',
|
||||
help: 'Show MiB/s',
|
||||
defaultsTo: false,
|
||||
)
|
||||
..addFlag(
|
||||
'nanoseconds-per-byte',
|
||||
abbr: 'n',
|
||||
help: 'Show ns/byte',
|
||||
defaultsTo: false,
|
||||
)
|
||||
..addFlag(
|
||||
'bytes-per-second',
|
||||
abbr: 'b',
|
||||
help: 'Show byte/s',
|
||||
defaultsTo: true,
|
||||
)
|
||||
..addFlag('verbose', abbr: 'v', help: 'Verbose output', defaultsTo: false)
|
||||
..addFlag(
|
||||
'aligned',
|
||||
abbr: 'a',
|
||||
help: 'Align results on initial numbers',
|
||||
defaultsTo: false,
|
||||
);
|
||||
|
||||
class Emitter {
|
||||
final bool bytesPerSecond;
|
||||
@@ -118,10 +117,9 @@ abstract class MemoryCopyBenchmark {
|
||||
// to avoid discarding results that almost, but not quite, reach the minimum
|
||||
// duration requested.
|
||||
final allowedJitter = Duration(
|
||||
microseconds:
|
||||
minDuration.inSeconds > 0
|
||||
? (minDuration.inMicroseconds * 0.1).floor()
|
||||
: 0,
|
||||
microseconds: minDuration.inSeconds > 0
|
||||
? (minDuration.inMicroseconds * 0.1).floor()
|
||||
: 0,
|
||||
);
|
||||
|
||||
final watch = Stopwatch()..start();
|
||||
@@ -475,11 +473,10 @@ void main(List<String> args) {
|
||||
List<int> lengthsInBytes = defaultLengthsInBytes;
|
||||
final emitter = Emitter(results);
|
||||
if (results['length'].isNotEmpty) {
|
||||
lengthsInBytes =
|
||||
(results['length'] as List<String>)
|
||||
.map(int.parse)
|
||||
.where((i) => i <= maxSizeInBytes)
|
||||
.toList();
|
||||
lengthsInBytes = (results['length'] as List<String>)
|
||||
.map(int.parse)
|
||||
.where((i) => i <= maxSizeInBytes)
|
||||
.toList();
|
||||
}
|
||||
final filter = results.rest.firstOrNull;
|
||||
final benchmarks = [
|
||||
|
||||
@@ -69,18 +69,14 @@ ResultClass forwardedClass() => notInlinedClass();
|
||||
@pragma('vm:prefer-inline')
|
||||
@pragma('wasm:prefer-inline')
|
||||
@pragma('dart2js:prefer-inline')
|
||||
({int result0, String result1}) inlinedRecordNamed() => (
|
||||
result0: input1,
|
||||
result1: input2,
|
||||
);
|
||||
({int result0, String result1}) inlinedRecordNamed() =>
|
||||
(result0: input1, result1: input2);
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
@pragma('wasm:never-inline')
|
||||
@pragma('dart2js:never-inline')
|
||||
({int result0, String result1}) notInlinedRecordNamed() => (
|
||||
result0: input1,
|
||||
result1: input2,
|
||||
);
|
||||
({int result0, String result1}) notInlinedRecordNamed() =>
|
||||
(result0: input1, result1: input2);
|
||||
|
||||
@pragma('vm:never-inline')
|
||||
@pragma('wasm:never-inline')
|
||||
|
||||
@@ -50,8 +50,10 @@ final Map<String, Lib> benchmarks = {
|
||||
'ListCopy': Lib(lib_ListCopy.loadLibrary, () => lib_ListCopy.main()),
|
||||
'MapCopy': Lib(lib_MapCopy.loadLibrary, () => lib_MapCopy.main([])),
|
||||
'MD5': Lib(lib_MD5.loadLibrary, () => lib_MD5.main()),
|
||||
'MultipleReturns':
|
||||
Lib(lib_MultipleReturns.loadLibrary, () => lib_MultipleReturns.main()),
|
||||
'MultipleReturns': Lib(
|
||||
lib_MultipleReturns.loadLibrary,
|
||||
() => lib_MultipleReturns.main(),
|
||||
),
|
||||
'RecordCollections': Lib(
|
||||
lib_RecordCollections.loadLibrary,
|
||||
() => lib_RecordCollections.main(),
|
||||
|
||||
@@ -23,8 +23,9 @@ Future<void> main(List<String> args) async {
|
||||
var events;
|
||||
try {
|
||||
tempDir = await Directory.systemTemp.createTemp();
|
||||
final timelinePath =
|
||||
tempDir.uri.resolve('Startup-timeline.json').toFilePath();
|
||||
final timelinePath = tempDir.uri
|
||||
.resolve('Startup-timeline.json')
|
||||
.toFilePath();
|
||||
final p = await Process.run(Platform.executable, [
|
||||
...Platform.executableArguments,
|
||||
'--timeline_recorder=file:$timelinePath',
|
||||
|
||||
@@ -137,8 +137,12 @@ class InstantiateSimple2DUiMatrix extends BenchmarkBase {
|
||||
void run() {
|
||||
double total = 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
total +=
|
||||
UiMatrix.simple2d(scaleX: 1.2, scaleY: 2.3, dx: 0.4, dy: 3.45).scaleX;
|
||||
total += UiMatrix.simple2d(
|
||||
scaleX: 1.2,
|
||||
scaleY: 2.3,
|
||||
dx: 0.4,
|
||||
dy: 3.45,
|
||||
).scaleX;
|
||||
}
|
||||
sink = total;
|
||||
}
|
||||
@@ -170,15 +174,14 @@ class InstantiateComplexUiMatrix extends BenchmarkBase {
|
||||
for (int i = 0; i < N; i++) {
|
||||
final cosAngle = math.cos(0.1);
|
||||
final sinAngle = math.sin(0.1);
|
||||
total +=
|
||||
UiMatrix.transform2d(
|
||||
scaleX: cosAngle,
|
||||
scaleY: cosAngle,
|
||||
k1: -sinAngle,
|
||||
k2: sinAngle,
|
||||
dx: 0.4,
|
||||
dy: 3.45,
|
||||
).scaleX;
|
||||
total += UiMatrix.transform2d(
|
||||
scaleX: cosAngle,
|
||||
scaleY: cosAngle,
|
||||
k1: -sinAngle,
|
||||
k2: sinAngle,
|
||||
dx: 0.4,
|
||||
dy: 3.45,
|
||||
).scaleX;
|
||||
}
|
||||
sink = total;
|
||||
}
|
||||
@@ -226,10 +229,9 @@ class MultiplyIdentityByIdentityUiMatrix extends BenchmarkBase {
|
||||
class MultiplySimply2DByIdentityMatrix4 extends BenchmarkBase {
|
||||
MultiplySimply2DByIdentityMatrix4()
|
||||
: super('UiMatrix.Multiply_Simple2DByIdentity_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 = Matrix4.identity();
|
||||
}
|
||||
|
||||
@@ -263,14 +265,12 @@ class MultiplySimply2DByIdentityUiMatrix extends BenchmarkBase {
|
||||
class MultiplySimple2DBySimple2DMatrix4 extends BenchmarkBase {
|
||||
MultiplySimple2DBySimple2DMatrix4()
|
||||
: super('UiMatrix.Multiply_Simple2DBySimple2D_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.5, 3.46)
|
||||
..scale(1.7, 2.8);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 = Matrix4.identity()
|
||||
..translate(0.5, 3.46)
|
||||
..scale(1.7, 2.8);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
@@ -301,14 +301,12 @@ class MultiplySimple2DBySimple2DUiMatrix extends BenchmarkBase {
|
||||
class MultiplyComplexByComplexMatrix4 extends BenchmarkBase {
|
||||
MultiplyComplexByComplexMatrix4()
|
||||
: super('UiMatrix.Multiply_ComplexByComplex_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
b4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.2)
|
||||
..translate(0.3, 3.44);
|
||||
a4 = Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
b4 = Matrix4.identity()
|
||||
..rotateZ(0.2)
|
||||
..translate(0.3, 3.44);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
@@ -385,10 +383,9 @@ class AddIdentityPlusIdentityUiMatrix extends BenchmarkBase {
|
||||
class AddSimple2DPlusIdentityMatrix4 extends BenchmarkBase {
|
||||
AddSimple2DPlusIdentityMatrix4()
|
||||
: super('UiMatrix.Add_Simple2DPlusIdentity_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 = Matrix4.identity();
|
||||
}
|
||||
@override
|
||||
@@ -420,14 +417,12 @@ class AddSimple2DPlusIdentityUiMatrix extends BenchmarkBase {
|
||||
class AddSimple2DPlusSimple2DMatrix4 extends BenchmarkBase {
|
||||
AddSimple2DPlusSimple2DMatrix4()
|
||||
: super('UiMatrix.Add_Simple2DPlusSimple2D_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.5, 3.46)
|
||||
..scale(1.7, 2.8);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
b4 = Matrix4.identity()
|
||||
..translate(0.5, 3.46)
|
||||
..scale(1.7, 2.8);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
@@ -458,14 +453,12 @@ class AddSimple2DPlusSimple2DUiMatrix extends BenchmarkBase {
|
||||
class AddComplexPlusComplexMatrix4 extends BenchmarkBase {
|
||||
AddComplexPlusComplexMatrix4()
|
||||
: super('UiMatrix.Add_ComplexPlusComplex_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
b4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.2)
|
||||
..translate(0.3, 3.44);
|
||||
a4 = Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
b4 = Matrix4.identity()
|
||||
..rotateZ(0.2)
|
||||
..translate(0.3, 3.44);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
@@ -540,10 +533,9 @@ class InversionIdentityUiMatrix extends BenchmarkBase {
|
||||
|
||||
class InversionSimple2DMatrix4 extends BenchmarkBase {
|
||||
InversionSimple2DMatrix4() : super('UiMatrix.Inversion_Simple2D_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -574,10 +566,9 @@ class InversionSimple2DUiMatrix extends BenchmarkBase {
|
||||
|
||||
class InversionComplexMatrix4 extends BenchmarkBase {
|
||||
InversionComplexMatrix4() : super('UiMatrix.Inversion_Complex_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
a4 = Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -646,10 +637,9 @@ class DeterminantIdentityUiMatrix extends BenchmarkBase {
|
||||
class DeterminantSimple2DMatrix4 extends BenchmarkBase {
|
||||
DeterminantSimple2DMatrix4()
|
||||
: super('UiMatrix.Determinant_Simple2D_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
a4 = Matrix4.identity()
|
||||
..translate(0.4, 3.45)
|
||||
..scale(1.2, 2.3);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
@@ -678,10 +668,9 @@ class DeterminantSimple2DUiMatrix extends BenchmarkBase {
|
||||
|
||||
class DeterminantComplexMatrix4 extends BenchmarkBase {
|
||||
DeterminantComplexMatrix4() : super('UiMatrix.Determinant_Complex_Matrix4') {
|
||||
a4 =
|
||||
Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
a4 = Matrix4.identity()
|
||||
..rotateZ(0.1)
|
||||
..translate(0.4, 3.45);
|
||||
}
|
||||
@override
|
||||
void run() {
|
||||
|
||||
@@ -27,12 +27,11 @@ class Utf8Decode extends BenchmarkBase {
|
||||
|
||||
static String _makeName(String language, int size, bool allowMalformed) {
|
||||
String name = 'Utf8Decode.$language.';
|
||||
name +=
|
||||
size >= 1000000
|
||||
? '${size ~/ 1000000}M'
|
||||
: size >= 1000
|
||||
? '${size ~/ 1000}k'
|
||||
: '$size';
|
||||
name += size >= 1000000
|
||||
? '${size ~/ 1000000}M'
|
||||
: size >= 1000
|
||||
? '${size ~/ 1000}k'
|
||||
: '$size';
|
||||
if (allowMalformed) name += '.malformed';
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,11 @@ class Utf8Encode extends BenchmarkBase {
|
||||
|
||||
static String _makeName(String language, int size) {
|
||||
String name = 'Utf8Encode.$language.';
|
||||
name +=
|
||||
size >= 1000000
|
||||
? '${size ~/ 1000000}M'
|
||||
: size >= 1000
|
||||
? '${size ~/ 1000}k'
|
||||
: '$size';
|
||||
name += size >= 1000000
|
||||
? '${size ~/ 1000000}M'
|
||||
: size >= 1000
|
||||
? '${size ~/ 1000}k'
|
||||
: '$size';
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user