Skip to content

Commit

Permalink
Adding benchmarks for running in golem (flutter#142)
Browse files Browse the repository at this point in the history
* first stab at a benchmark for running in golem.
  • Loading branch information
sigurdm authored Dec 14, 2018
1 parent ff5eb4c commit 74f62c0
Show file tree
Hide file tree
Showing 46 changed files with 1,646 additions and 6 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,29 @@ jobs:
dart: dev
- stage: format_analyzer_tests
name: "SDK: dev - DIR: protoc_plugin - TASKS: [make protos, dartanalyzer --fatal-infos --fatal-warnings .]"
script: ./tool/travis.sh command dartanalyzer_0
script: ./tool/travis.sh command_0 dartanalyzer_0
env: PKG="protoc_plugin"
dart: dev
- stage: format_analyzer_tests
name: "SDK: stable - DIR: protoc_plugin - TASKS: [make protos, dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]"
script: ./tool/travis.sh command dartfmt dartanalyzer_1
script: ./tool/travis.sh command_0 dartfmt dartanalyzer_1
env: PKG="protoc_plugin"
dart: stable
- stage: format_analyzer_tests
name: "SDK: stable - DIR: protoc_plugin - TASKS: [make protos, pub run test]"
script: ./tool/travis.sh command test
script: ./tool/travis.sh command_0 test
env: PKG="protoc_plugin"
dart: stable
- stage: format_analyzer_tests
name: "SDK: dev - DIR: protoc_plugin - TASKS: [make protos, pub run test]"
script: ./tool/travis.sh command test
script: ./tool/travis.sh command_0 test
env: PKG="protoc_plugin"
dart: dev
- stage: format_analyzer_tests
name: "SDK: stable - DIR: query_benchmark - TASKS: [./compile_protos.sh, dartfmt -n --set-exit-if-changed ., dartanalyzer --fatal-warnings .]"
script: ./tool/travis.sh command_1 dartfmt dartanalyzer_1
env: PKG="query_benchmark"
dart: stable

stages:
- format_analyzer_tests
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
exclude:
- benchmarks/query_benchmark/**
19 changes: 19 additions & 0 deletions query_benchmark/bin/decode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2018, 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 'package:query_benchmark/generated/f0.pb.dart' as f0;
import 'package:query_benchmark/benchmark.dart';
import 'package:query_benchmark/readfile.dart';

main() {
String path = const String.fromEnvironment('testfile') ?? 'testdata/500.pb';

List<int> encoded = readfile(path);
print(
formatReport(
title: 'protobuf_decode',
duration: measure(() => f0.A0.fromBuffer(encoded)),
),
);
}
21 changes: 21 additions & 0 deletions query_benchmark/bin/decode_json.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2018, 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 'package:query_benchmark/generated/f0.pb.dart' as f0;
import 'package:query_benchmark/benchmark.dart';
import 'package:query_benchmark/readfile.dart';

main() {
String path = const String.fromEnvironment('testfile') ?? 'testdata/500.pb';

List<int> encoded = readfile(path);
f0.A0 a = f0.A0.fromBuffer(encoded);
String json = a.writeToJson();
print(
formatReport(
title: 'protobuf_decode_json',
duration: measure(() => f0.A0.fromJson(json)),
),
);
}
19 changes: 19 additions & 0 deletions query_benchmark/bin/encode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2018, 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 'package:query_benchmark/generated/f0.pb.dart' as f0;
import 'package:query_benchmark/benchmark.dart';
import 'package:query_benchmark/readfile.dart';

main() {
String path = const String.fromEnvironment('testfile') ?? 'testdata/500.pb';
List<int> encoded = readfile(path);
f0.A0 a = f0.A0.fromBuffer(encoded);
print(
formatReport(
title: 'protobuf_encode',
duration: measure(() => a.writeToBuffer()),
),
);
}
20 changes: 20 additions & 0 deletions query_benchmark/bin/encode_json.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2018, 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 'package:query_benchmark/generated/f0.pb.dart' as f0;
import 'package:query_benchmark/benchmark.dart';
import 'package:query_benchmark/readfile.dart';

main() {
String path = const String.fromEnvironment('testfile') ?? 'testdata/500.pb';

List<int> encoded = readfile(path);
f0.A0 a = f0.A0.fromBuffer(encoded);
print(
formatReport(
title: 'protobuf_encode_json',
duration: measure(() => a.writeToJson()),
),
);
}
27 changes: 27 additions & 0 deletions query_benchmark/bin/set_nested_value.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2018, 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 'package:query_benchmark/generated/f0.pb.dart' as f0;
import 'package:query_benchmark/generated/f2.pb.dart' as f2;
import 'package:query_benchmark/generated/f19.pb.dart' as f19;
import 'package:query_benchmark/benchmark.dart';
import 'package:query_benchmark/readfile.dart';

main() {
String path = const String.fromEnvironment('testfile') ?? 'testdata/500.pb';

List<int> encoded = readfile(path);
f0.A0 a = f0.A0.fromBuffer(encoded)..freeze();
print(
formatReport(
title: 'protobuf_decode',
duration: measure(() => a.copyWith((f0.A0 a0Builder) {
a0Builder.a4.last = a0Builder.a4.last.copyWith((f2.A1 a1builder) {
a1builder.a378.copyWith(
(f19.A220 a220builder) => a220builder.a234 = 'new_value');
});
})),
),
);
}
5 changes: 5 additions & 0 deletions query_benchmark/compile_protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
rm -rf lib/generated
mkdir lib/generated
protoc --dart_out=lib/generated --plugin=protoc-gen-dart=run_protoc_plugin.sh -Iprotos protos/*.proto
dartfmt -w lib/generated
22 changes: 22 additions & 0 deletions query_benchmark/lib/benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2018, 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.

/// Returns the average time to execute [f] over [iterations] repetitions.
///
/// Will first run [f] [warmupIterations] times to warm up the runtime.
Duration measure(void Function() f,
{int warmupIterations = 100, int iterations = 1000}) {
for (int i = 0; i < warmupIterations; i++) {
f();
}
var s = Stopwatch()..start();
for (int i = 0; i < iterations; i++) {
f();
}
return s.elapsed ~/ iterations;
}

String formatReport({String title, Duration duration}) {
return "RunTimeRaw($title): ${duration.inMicroseconds} us";
}
5 changes: 5 additions & 0 deletions query_benchmark/lib/readfile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2018, 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.

export 'readfile_vm.dart' if (dart.library.js) 'readfile_d8.dart' show readfile;
21 changes: 21 additions & 0 deletions query_benchmark/lib/readfile_d8.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2018, 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' as js;

import 'dart:typed_data';

/// Reads the file at the given [path] and return its contents in a List<int>.
Uint8List readfile(String path) {
// d8 specific implementation.
js.JsObject jsArrayBuffer = js.context.callMethod('readbuffer', [path]);
int length = jsArrayBuffer['byteLength'];
js.JsObject jsInt8View =
new js.JsObject(js.context['Int8Array'], [jsArrayBuffer]);
Uint8List result = new Uint8List(length);
for (int i = 0; i < length; i++) {
result[i] = jsInt8View[i];
}
return result;
}
9 changes: 9 additions & 0 deletions query_benchmark/lib/readfile_vm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2018, 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:io';

List<int> readfile(String path) {
return new File(path).readAsBytesSync();
}
11 changes: 11 additions & 0 deletions query_benchmark/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See https://github.com/dart-lang/mono_repo for details
dart:
- stable

stages:
- format_analyzer_tests:
- group:
- command: ./compile_protos.sh
- dartfmt
- dartanalyzer: --fatal-warnings .
dart: [stable]
22 changes: 22 additions & 0 deletions query_benchmark/protos/f0.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2018, 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.

syntax = "proto2";
package a0.a1.a2.a3;
import "f2.proto";
import "f3.proto";
message A0 {
repeated .a0.a1.a2.a3.A1 a4 = 1;
optional string a5 = 3;
enum A2 {
A3 = 0;
A4 = 1;
A5 = 2;
A6 = 3;
A7 = 4;
A8 = 5;
}
optional A2 a6 = 2;
optional a7.A9 a8 = 4;
}
43 changes: 43 additions & 0 deletions query_benchmark/protos/f1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2018, 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.

syntax = "proto2";
package a0.a1.a274;
import "f5.proto";
message A313 {
optional int32 a90 = 1;
optional int32 a275 = 2;
}
message A314 {
repeated A313 a276 = 1;
}
message A315 {
optional string a277 = 1;
optional a10.A113.A59 a99 = 2;
optional int64 a278 = 3;
repeated string a279 = 4;
}
message A316 {
optional string a280 = 1;
optional int64 a281 = 2;
repeated A315 a282 = 3;
}
message A317 {
repeated A316 a283 = 1;
}
extend a10.A56 {
repeated A313 a276 = 134096400;
optional A314 a284 = 141473177;
}
message A318 {
message A319 {
optional int32 a285 = 1;
optional string a54 = 2;
}
repeated A319 a286 = 1;
}
extend a10.A57 {
optional int32 a287 = 134096400;
optional A318 a288 = 185706300;
}
21 changes: 21 additions & 0 deletions query_benchmark/protos/f10.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2018, 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.

syntax = "proto2";
package a10.a68;
message A102 {
optional string a52 = 1;
optional uint64 a69 = 2;
optional uint64 a70 = 3;
optional uint64 a71 = 4;
}
message A103 {
optional string a52 = 1;
optional uint64 a72 = 2;
repeated A102 a73 = 3;
}
message A104 {
repeated A103 message = 1;
optional string a74 = 2;
}
17 changes: 17 additions & 0 deletions query_benchmark/protos/f11.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2018, 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.

syntax = "proto2";
package a0.a1;
import "f12.proto";
message A105 {
optional string a75 = 1;
};
message A106 {
optional A105 a76 = 1;
optional string a77 = 3;
};
message A107 {
optional string a78 = 1;
}
Loading

0 comments on commit 74f62c0

Please sign in to comment.