diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 579ab68f7..fa95f8605 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -68,16 +68,16 @@ jobs: working-directory: protobuf run: dart analyze test job_003: - name: "format_analyze; linux; Dart dev; PKGS: api_benchmark, query_benchmark; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `./compile_protos.sh`, `dart analyze --fatal-infos`" + name: "format_analyze; linux; Dart dev; PKG: api_benchmark; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `./compile_protos.sh`, `dart analyze --fatal-infos`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:api_benchmark-query_benchmark;commands:format-command_0-command_1-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:api_benchmark;commands:format-command_0-command_1-analyze_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:api_benchmark-query_benchmark + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:api_benchmark os:ubuntu-latest;pub-cache-hosted;sdk:dev os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest @@ -107,28 +107,47 @@ jobs: if: "always() && steps.api_benchmark_pub_upgrade.conclusion == 'success'" working-directory: api_benchmark run: dart analyze --fatal-infos - - id: query_benchmark_pub_upgrade - name: query_benchmark; dart pub upgrade + job_004: + name: "format_analyze; linux; Dart dev; PKG: benchmarks; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `./tool/compile_protos.sh`, `dart analyze --fatal-infos`" + runs-on: ubuntu-latest + steps: + - name: Cache Pub hosted dependencies + uses: actions/cache@v3 + with: + path: "~/.pub-cache/hosted" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:benchmarks;commands:format-command_0-command_2-analyze_0" + restore-keys: | + os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:benchmarks + os:ubuntu-latest;pub-cache-hosted;sdk:dev + os:ubuntu-latest;pub-cache-hosted + os:ubuntu-latest + - uses: dart-lang/setup-dart@v1.3 + with: + sdk: dev + - id: checkout + uses: actions/checkout@v3.0.0 + - id: benchmarks_pub_upgrade + name: benchmarks; dart pub upgrade if: "always() && steps.checkout.conclusion == 'success'" - working-directory: query_benchmark + working-directory: benchmarks run: dart pub upgrade - - name: "query_benchmark; dart format --output=none --set-exit-if-changed ." - if: "always() && steps.query_benchmark_pub_upgrade.conclusion == 'success'" - working-directory: query_benchmark + - name: "benchmarks; dart format --output=none --set-exit-if-changed ." + if: "always() && steps.benchmarks_pub_upgrade.conclusion == 'success'" + working-directory: benchmarks run: "dart format --output=none --set-exit-if-changed ." - - name: query_benchmark; ./../tool/setup.sh - if: "always() && steps.query_benchmark_pub_upgrade.conclusion == 'success'" - working-directory: query_benchmark + - name: benchmarks; ./../tool/setup.sh + if: "always() && steps.benchmarks_pub_upgrade.conclusion == 'success'" + working-directory: benchmarks run: ./../tool/setup.sh - - name: query_benchmark; ./compile_protos.sh - if: "always() && steps.query_benchmark_pub_upgrade.conclusion == 'success'" - working-directory: query_benchmark - run: ./compile_protos.sh - - name: "query_benchmark; dart analyze --fatal-infos" - if: "always() && steps.query_benchmark_pub_upgrade.conclusion == 'success'" - working-directory: query_benchmark + - name: benchmarks; ./tool/compile_protos.sh + if: "always() && steps.benchmarks_pub_upgrade.conclusion == 'success'" + working-directory: benchmarks + run: ./tool/compile_protos.sh + - name: "benchmarks; dart analyze --fatal-infos" + if: "always() && steps.benchmarks_pub_upgrade.conclusion == 'success'" + working-directory: benchmarks run: dart analyze --fatal-infos - job_004: + job_005: name: "format_analyze; linux; Dart dev; PKG: protobuf; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos`" runs-on: ubuntu-latest steps: @@ -160,7 +179,7 @@ jobs: if: "always() && steps.protobuf_pub_upgrade.conclusion == 'success'" working-directory: protobuf run: dart analyze --fatal-infos - job_005: + job_006: name: "format_analyze; linux; Dart dev; PKG: protoc_plugin; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `make protos`, `dart analyze --fatal-infos`" runs-on: ubuntu-latest steps: @@ -168,7 +187,7 @@ jobs: uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:format-command_0-command_2-analyze_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:format-command_0-command_3-analyze_0" restore-keys: | os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin os:ubuntu-latest;pub-cache-hosted;sdk:dev @@ -200,7 +219,7 @@ jobs: if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'" working-directory: protoc_plugin run: dart analyze --fatal-infos - job_006: + job_007: name: "run_tests; linux; Dart 2.12.0; PKG: protobuf; `dart test`" runs-on: ubuntu-latest steps: @@ -234,7 +253,8 @@ jobs: - job_003 - job_004 - job_005 - job_007: + - job_006 + job_008: name: "run_tests; linux; Dart 2.12.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test`" runs-on: ubuntu-latest steps: @@ -242,7 +262,7 @@ jobs: uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin;commands:command_0-command_2-test" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin;commands:command_0-command_3-test" restore-keys: | os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0 @@ -276,7 +296,8 @@ jobs: - job_003 - job_004 - job_005 - job_008: + - job_006 + job_009: name: "run_tests; linux; Dart dev; PKG: protobuf; `dart test`" runs-on: ubuntu-latest steps: @@ -310,7 +331,8 @@ jobs: - job_003 - job_004 - job_005 - job_009: + - job_006 + job_010: name: "run_tests; linux; Dart dev; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test`" runs-on: ubuntu-latest steps: @@ -318,7 +340,7 @@ jobs: uses: actions/cache@v3 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:command_0-command_2-test" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:command_0-command_3-test" restore-keys: | os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin os:ubuntu-latest;pub-cache-hosted;sdk:dev @@ -352,7 +374,8 @@ jobs: - job_003 - job_004 - job_005 - job_010: + - job_006 + job_011: name: "run_tests; osx; Dart 2.12.0; PKG: protobuf; `dart test`" runs-on: macos-latest steps: @@ -386,7 +409,8 @@ jobs: - job_003 - job_004 - job_005 - job_011: + - job_006 + job_012: name: "run_tests; osx; Dart dev; PKG: protobuf; `dart test`" runs-on: macos-latest steps: @@ -420,7 +444,8 @@ jobs: - job_003 - job_004 - job_005 - job_012: + - job_006 + job_013: name: "run_tests; windows; Dart 2.12.0; PKG: protobuf; `dart test`" runs-on: windows-latest steps: @@ -444,7 +469,8 @@ jobs: - job_003 - job_004 - job_005 - job_013: + - job_006 + job_014: name: "run_tests; windows; Dart dev; PKG: protobuf; `dart test`" runs-on: windows-latest steps: @@ -468,3 +494,4 @@ jobs: - job_003 - job_004 - job_005 + - job_006 diff --git a/.gitignore b/.gitignore index e83ffaa2f..b853dd090 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ build/ **/lib/generated/** packages pubspec.lock +benchmarks/out diff --git a/benchmarks/README.md b/benchmarks/README.md new file mode 100644 index 000000000..7d3a449e5 --- /dev/null +++ b/benchmarks/README.md @@ -0,0 +1,20 @@ +## Running benchmarks + +- Compile protos with `./tool/compile_protos.sh` + +- **JIT:** Run benchmark programs in `bin/`, e.g. `dart bin/from_binary.dart` + +- **AOT and JS:** + + - Compile benchmark programs to native, JS, and JIT snapshots with + `./tool/compile_benchmarks.dart` + + - Run benchmark programs in `out/`: + - AOT: `./out/from_binary.exe` + - JS: `d8 $DART_SDK/lib/_internal/js_runtime/lib/preambles/d8.js out/from_binary.js` + +## Development + +`protoc_version` file specifies the version of protoc Golem will use when +building the benchmarks, and allows updating the protoc version without +changing Golem. diff --git a/benchmarks/analysis_options.yaml b/benchmarks/analysis_options.yaml new file mode 100644 index 000000000..0476eb223 --- /dev/null +++ b/benchmarks/analysis_options.yaml @@ -0,0 +1,5 @@ +include: package:lints/recommended.yaml + +linter: + rules: + - directives_ordering diff --git a/benchmarks/bin/from_binary.dart b/benchmarks/bin/from_binary.dart new file mode 100644 index 000000000..8d5990b17 --- /dev/null +++ b/benchmarks/bin/from_binary.dart @@ -0,0 +1,44 @@ +// 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:typed_data'; + +import 'package:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final Uint8List _message1Proto2Input; + final Uint8List _message1Proto3Input; + final Uint8List _message2Input; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2Input = Uint8List.fromList(message1Proto2Input), + _message1Proto3Input = Uint8List.fromList(message1Proto3Input), + _message2Input = Uint8List.fromList(message2Input), + super(name); + + @override + void run() { + p2.GoogleMessage1.fromBuffer(_message1Proto2Input); + p3.GoogleMessage1.fromBuffer(_message1Proto3Input); + GoogleMessage2.fromBuffer(_message2Input); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('from_binary', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/from_json_string.dart b/benchmarks/bin/from_json_string.dart new file mode 100644 index 000000000..02e22a276 --- /dev/null +++ b/benchmarks/bin/from_json_string.dart @@ -0,0 +1,45 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final String _message1Proto2JsonString; + final String _message1Proto3JsonString; + final String _message2JsonString; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2JsonString = + p2.GoogleMessage1.fromBuffer(message1Proto2Input).writeToJson(), + _message1Proto3JsonString = + p3.GoogleMessage1.fromBuffer(message1Proto3Input).writeToJson(), + _message2JsonString = + GoogleMessage2.fromBuffer(message2Input).writeToJson(), + super(name); + + @override + void run() { + p2.GoogleMessage1.fromJson(_message1Proto2JsonString); + p3.GoogleMessage1.fromJson(_message1Proto3JsonString); + GoogleMessage2.fromJson(_message2JsonString); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('from_json_string', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/from_proto3_json_object.dart b/benchmarks/bin/from_proto3_json_object.dart new file mode 100644 index 000000000..1ca424ac2 --- /dev/null +++ b/benchmarks/bin/from_proto3_json_object.dart @@ -0,0 +1,47 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final Object? _message1Proto2Proto3JsonObject; + final Object? _message1Proto3Proto3JsonObject; + final Object? _message2Proto3JsonObject; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2Proto3JsonObject = + p2.GoogleMessage1.fromBuffer(message1Proto2Input).toProto3Json(), + _message1Proto3Proto3JsonObject = + p3.GoogleMessage1.fromBuffer(message1Proto3Input).toProto3Json(), + _message2Proto3JsonObject = + GoogleMessage2.fromBuffer(message2Input).toProto3Json(), + super(name); + + @override + void run() { + p2.GoogleMessage1.create() + .mergeFromProto3Json(_message1Proto2Proto3JsonObject); + p3.GoogleMessage1.create() + .mergeFromProto3Json(_message1Proto3Proto3JsonObject); + GoogleMessage2.create().mergeFromProto3Json(_message2Proto3JsonObject); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('from_proto3_json_object', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/from_proto3_json_string.dart b/benchmarks/bin/from_proto3_json_string.dart new file mode 100644 index 000000000..f3c8c1e04 --- /dev/null +++ b/benchmarks/bin/from_proto3_json_string.dart @@ -0,0 +1,50 @@ +// 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:convert' show jsonDecode, jsonEncode; + +import 'package:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final String _message1Proto2Proto3JsonString; + final String _message1Proto3Proto3JsonString; + final String _message2Proto3JsonString; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2Proto3JsonString = jsonEncode( + p2.GoogleMessage1.fromBuffer(message1Proto2Input).toProto3Json()), + _message1Proto3Proto3JsonString = jsonEncode( + p3.GoogleMessage1.fromBuffer(message1Proto3Input).toProto3Json()), + _message2Proto3JsonString = + jsonEncode(GoogleMessage2.fromBuffer(message2Input).toProto3Json()), + super(name); + + @override + void run() { + p2.GoogleMessage1.create() + .mergeFromProto3Json(jsonDecode(_message1Proto2Proto3JsonString)); + p3.GoogleMessage1.create() + .mergeFromProto3Json(jsonDecode(_message1Proto3Proto3JsonString)); + GoogleMessage2.create() + .mergeFromProto3Json(jsonDecode(_message2Proto3JsonString)); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('from_proto3_json_string', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/hash_code.dart b/benchmarks/bin/hash_code.dart new file mode 100644 index 000000000..5d1e01e67 --- /dev/null +++ b/benchmarks/bin/hash_code.dart @@ -0,0 +1,42 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final p2.GoogleMessage1 _message1Proto2; + final p3.GoogleMessage1 _message1Proto3; + final GoogleMessage2 _message2; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), + _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), + _message2 = GoogleMessage2.fromBuffer(message2Input), + super(name); + + @override + void run() { + _message1Proto2.hashCode; + _message1Proto3.hashCode; + _message2.hashCode; + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark( + 'hash_code', message1Proto2Input, message1Proto3Input, message2Input) + .report(); +} diff --git a/benchmarks/bin/query_decode_binary.dart b/benchmarks/bin/query_decode_binary.dart new file mode 100644 index 000000000..80a8123c2 --- /dev/null +++ b/benchmarks/bin/query_decode_binary.dart @@ -0,0 +1,23 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f0.pb.dart' as f0; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final List _input; + + Benchmark(String name, this._input) : super(name); + + @override + void run() { + f0.A0.fromBuffer(_input); + } +} + +void main() { + List encoded = readfile('datasets/query_benchmark.pb'); + Benchmark('query_decode_binary', encoded).report(); +} diff --git a/benchmarks/bin/query_decode_json.dart b/benchmarks/bin/query_decode_json.dart new file mode 100644 index 000000000..1909b4b1c --- /dev/null +++ b/benchmarks/bin/query_decode_json.dart @@ -0,0 +1,25 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f0.pb.dart' as f0; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final String _input; + + Benchmark(String name, List input) + : _input = f0.A0.fromBuffer(input).writeToJson(), + super(name); + + @override + void run() { + f0.A0.fromJson(_input); + } +} + +void main() { + List encoded = readfile('datasets/query_benchmark.pb'); + Benchmark('query_decode_json', encoded).report(); +} diff --git a/benchmarks/bin/query_encode_binary.dart b/benchmarks/bin/query_encode_binary.dart new file mode 100644 index 000000000..ff0b3b189 --- /dev/null +++ b/benchmarks/bin/query_encode_binary.dart @@ -0,0 +1,25 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f0.pb.dart' as f0; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final f0.A0 _input; + + Benchmark(String name, List input) + : _input = f0.A0.fromBuffer(input), + super(name); + + @override + void run() { + _input.writeToBuffer(); + } +} + +void main() { + List encoded = readfile('datasets/query_benchmark.pb'); + Benchmark('query_encode_binary', encoded).report(); +} diff --git a/benchmarks/bin/query_encode_json.dart b/benchmarks/bin/query_encode_json.dart new file mode 100644 index 000000000..17789d554 --- /dev/null +++ b/benchmarks/bin/query_encode_json.dart @@ -0,0 +1,25 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f0.pb.dart' as f0; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final f0.A0 _input; + + Benchmark(String name, List input) + : _input = f0.A0.fromBuffer(input), + super(name); + + @override + void run() { + _input.writeToJson(); + } +} + +void main() { + List encoded = readfile('datasets/query_benchmark.pb'); + Benchmark('query_encode_json', encoded).report(); +} diff --git a/benchmarks/bin/query_set_nested_value.dart b/benchmarks/bin/query_set_nested_value.dart new file mode 100644 index 000000000..0e9bf5c24 --- /dev/null +++ b/benchmarks/bin/query_set_nested_value.dart @@ -0,0 +1,34 @@ +// 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:protobuf/protobuf.dart'; +import 'package:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f0.pb.dart' as f0; +import 'package:protobuf_benchmarks/generated/f19.pb.dart' as f19; +import 'package:protobuf_benchmarks/generated/f2.pb.dart' as f2; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final f0.A0 _input; + + Benchmark(String name, List input) + : _input = f0.A0.fromBuffer(input)..freeze(), + super(name); + + @override + void run() { + // ignore: unused_result + _input.rebuild((f0.A0 a0Builder) { + a0Builder.a4.last = a0Builder.a4.last.rebuild((f2.A1 a1builder) { + a1builder.a378 = a1builder.a378 + .rebuild((f19.A220 a220builder) => a220builder.a234 = 'new_value'); + }); + }); + } +} + +void main() { + List encoded = readfile('datasets/query_benchmark.pb'); + Benchmark('query_set_nested_value', encoded).report(); +} diff --git a/benchmarks/bin/to_binary.dart b/benchmarks/bin/to_binary.dart new file mode 100644 index 000000000..d008c4d0c --- /dev/null +++ b/benchmarks/bin/to_binary.dart @@ -0,0 +1,42 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final p2.GoogleMessage1 _message1Proto2; + final p3.GoogleMessage1 _message1Proto3; + final GoogleMessage2 _message2; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), + _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), + _message2 = GoogleMessage2.fromBuffer(message2Input), + super(name); + + @override + void run() { + _message1Proto2.writeToBuffer(); + _message1Proto3.writeToBuffer(); + _message2.writeToBuffer(); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark( + 'to_binary', message1Proto2Input, message1Proto3Input, message2Input) + .report(); +} diff --git a/benchmarks/bin/to_json_string.dart b/benchmarks/bin/to_json_string.dart new file mode 100644 index 000000000..32df02cf2 --- /dev/null +++ b/benchmarks/bin/to_json_string.dart @@ -0,0 +1,42 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final p2.GoogleMessage1 _message1Proto2; + final p3.GoogleMessage1 _message1Proto3; + final GoogleMessage2 _message2; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), + _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), + _message2 = GoogleMessage2.fromBuffer(message2Input), + super(name); + + @override + void run() { + _message1Proto2.writeToJson(); + _message1Proto3.writeToJson(); + _message2.writeToJson(); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('to_json_string', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/to_proto3_json_object.dart b/benchmarks/bin/to_proto3_json_object.dart new file mode 100644 index 000000000..8c23790c1 --- /dev/null +++ b/benchmarks/bin/to_proto3_json_object.dart @@ -0,0 +1,42 @@ +// 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:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final p2.GoogleMessage1 _message1Proto2; + final p3.GoogleMessage1 _message1Proto3; + final GoogleMessage2 _message2; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), + _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), + _message2 = GoogleMessage2.fromBuffer(message2Input), + super(name); + + @override + void run() { + _message1Proto2.toProto3Json(); + _message1Proto3.toProto3Json(); + _message2.toProto3Json(); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('to_proto3_json_object', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/benchmarks/bin/to_proto3_json_string.dart b/benchmarks/bin/to_proto3_json_string.dart new file mode 100644 index 000000000..1a3407d27 --- /dev/null +++ b/benchmarks/bin/to_proto3_json_string.dart @@ -0,0 +1,44 @@ +// 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:convert' show jsonEncode; + +import 'package:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/google_message1_proto2.pb.dart' + as p2; +import 'package:protobuf_benchmarks/generated/google_message1_proto3.pb.dart' + as p3; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; +import 'package:protobuf_benchmarks/readfile.dart'; + +class Benchmark extends BenchmarkBase { + final p2.GoogleMessage1 _message1Proto2; + final p3.GoogleMessage1 _message1Proto3; + final GoogleMessage2 _message2; + + Benchmark(String name, List message1Proto2Input, + List message1Proto3Input, List message2Input) + : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), + _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), + _message2 = GoogleMessage2.fromBuffer(message2Input), + super(name); + + @override + void run() { + jsonEncode(_message1Proto2.toProto3Json()); + jsonEncode(_message1Proto3.toProto3Json()); + jsonEncode(_message2.toProto3Json()); + } +} + +void main() { + List message1Proto2Input = + readfile('datasets/google_message1_proto2.pb'); + List message1Proto3Input = + readfile('datasets/google_message1_proto3.pb'); + List message2Input = readfile('datasets/google_message2.pb'); + Benchmark('to_proto3_json_string', message1Proto2Input, message1Proto3Input, + message2Input) + .report(); +} diff --git a/protobuf_benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb b/benchmarks/datasets/google_message1_proto2.pb similarity index 78% rename from protobuf_benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb rename to benchmarks/datasets/google_message1_proto2.pb index f6fe7848c..bc0f064cc 100644 Binary files a/protobuf_benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb and b/benchmarks/datasets/google_message1_proto2.pb differ diff --git a/protobuf_benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb b/benchmarks/datasets/google_message1_proto3.pb similarity index 78% rename from protobuf_benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb rename to benchmarks/datasets/google_message1_proto3.pb index 4955bed31..bc0f064cc 100644 Binary files a/protobuf_benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb and b/benchmarks/datasets/google_message1_proto3.pb differ diff --git a/protobuf_benchmarks/datasets/google_message2/dataset.google_message2.pb b/benchmarks/datasets/google_message2.pb similarity index 99% rename from protobuf_benchmarks/datasets/google_message2/dataset.google_message2.pb rename to benchmarks/datasets/google_message2.pb index 3fa0e49e5..06c09441b 100644 Binary files a/protobuf_benchmarks/datasets/google_message2/dataset.google_message2.pb and b/benchmarks/datasets/google_message2.pb differ diff --git a/query_benchmark/testdata/500.pb b/benchmarks/datasets/query_benchmark.pb similarity index 100% rename from query_benchmark/testdata/500.pb rename to benchmarks/datasets/query_benchmark.pb diff --git a/benchmarks/lib/benchmark_base.dart b/benchmarks/lib/benchmark_base.dart new file mode 100644 index 000000000..cec44ccd5 --- /dev/null +++ b/benchmarks/lib/benchmark_base.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2022, 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:benchmark_harness/benchmark_harness.dart' as bh; + +/// A subclass of [bh.BenchmarkBase] with a few changes: +/// +/// - Work around https://github.com/dart-lang/benchmark_harness/issues/30 by +/// dividing the result by 10. +/// +/// - Report the results as "RunTimeRaw" instead of "RunTime". What +/// benchmark_harness calls "RunTime" is called "RunTimeRaw" in Golem. +/// +/// - Add "protobuf_" prefix to test names. This is to make it easier to see +/// what the benchmarks are about in Golem UI. +/// +abstract class BenchmarkBase extends bh.BenchmarkBase { + BenchmarkBase(String name) : super(name, emitter: const _ResultPrinter()); + + @override + double measure() { + return super.measure() / 10; + } +} + +class _ResultPrinter implements bh.ScoreEmitter { + const _ResultPrinter() : super(); + + @override + void emit(String testName, double value) { + // Same as the default, but prints "RunTimeRaw" instead of "RunTime" + print('protobuf_$testName(RunTimeRaw): $value us.'); + } +} diff --git a/protobuf_benchmarks/lib/readfile.dart b/benchmarks/lib/readfile.dart similarity index 100% rename from protobuf_benchmarks/lib/readfile.dart rename to benchmarks/lib/readfile.dart diff --git a/protobuf_benchmarks/lib/readfile_d8.dart b/benchmarks/lib/readfile_d8.dart similarity index 100% rename from protobuf_benchmarks/lib/readfile_d8.dart rename to benchmarks/lib/readfile_d8.dart diff --git a/protobuf_benchmarks/lib/readfile_vm.dart b/benchmarks/lib/readfile_vm.dart similarity index 100% rename from protobuf_benchmarks/lib/readfile_vm.dart rename to benchmarks/lib/readfile_vm.dart diff --git a/query_benchmark/mono_pkg.yaml b/benchmarks/mono_pkg.yaml similarity index 82% rename from query_benchmark/mono_pkg.yaml rename to benchmarks/mono_pkg.yaml index b23af8b06..df3f45473 100644 --- a/query_benchmark/mono_pkg.yaml +++ b/benchmarks/mono_pkg.yaml @@ -5,6 +5,6 @@ stages: - group: - format - command: ./../tool/setup.sh - - command: ./compile_protos.sh + - command: ./tool/compile_protos.sh - analyze: --fatal-infos sdk: dev diff --git a/benchmarks/protoc_version b/benchmarks/protoc_version new file mode 100644 index 000000000..c598172d8 --- /dev/null +++ b/benchmarks/protoc_version @@ -0,0 +1 @@ +21.2 diff --git a/protobuf_benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.proto b/benchmarks/protos/google_message1_proto2.proto similarity index 100% rename from protobuf_benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.proto rename to benchmarks/protos/google_message1_proto2.proto diff --git a/protobuf_benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.proto b/benchmarks/protos/google_message1_proto3.proto similarity index 100% rename from protobuf_benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.proto rename to benchmarks/protos/google_message1_proto3.proto diff --git a/protobuf_benchmarks/datasets/google_message2/benchmark_message2.proto b/benchmarks/protos/google_message2.proto similarity index 100% rename from protobuf_benchmarks/datasets/google_message2/benchmark_message2.proto rename to benchmarks/protos/google_message2.proto diff --git a/query_benchmark/protos/f0.proto b/benchmarks/protos/query_benchmark/f0.proto similarity index 100% rename from query_benchmark/protos/f0.proto rename to benchmarks/protos/query_benchmark/f0.proto diff --git a/query_benchmark/protos/f1.proto b/benchmarks/protos/query_benchmark/f1.proto similarity index 100% rename from query_benchmark/protos/f1.proto rename to benchmarks/protos/query_benchmark/f1.proto diff --git a/query_benchmark/protos/f10.proto b/benchmarks/protos/query_benchmark/f10.proto similarity index 100% rename from query_benchmark/protos/f10.proto rename to benchmarks/protos/query_benchmark/f10.proto diff --git a/query_benchmark/protos/f11.proto b/benchmarks/protos/query_benchmark/f11.proto similarity index 100% rename from query_benchmark/protos/f11.proto rename to benchmarks/protos/query_benchmark/f11.proto diff --git a/query_benchmark/protos/f12.proto b/benchmarks/protos/query_benchmark/f12.proto similarity index 100% rename from query_benchmark/protos/f12.proto rename to benchmarks/protos/query_benchmark/f12.proto diff --git a/query_benchmark/protos/f13.proto b/benchmarks/protos/query_benchmark/f13.proto similarity index 100% rename from query_benchmark/protos/f13.proto rename to benchmarks/protos/query_benchmark/f13.proto diff --git a/query_benchmark/protos/f14.proto b/benchmarks/protos/query_benchmark/f14.proto similarity index 100% rename from query_benchmark/protos/f14.proto rename to benchmarks/protos/query_benchmark/f14.proto diff --git a/query_benchmark/protos/f15.proto b/benchmarks/protos/query_benchmark/f15.proto similarity index 100% rename from query_benchmark/protos/f15.proto rename to benchmarks/protos/query_benchmark/f15.proto diff --git a/query_benchmark/protos/f16.proto b/benchmarks/protos/query_benchmark/f16.proto similarity index 100% rename from query_benchmark/protos/f16.proto rename to benchmarks/protos/query_benchmark/f16.proto diff --git a/query_benchmark/protos/f17.proto b/benchmarks/protos/query_benchmark/f17.proto similarity index 100% rename from query_benchmark/protos/f17.proto rename to benchmarks/protos/query_benchmark/f17.proto diff --git a/query_benchmark/protos/f18.proto b/benchmarks/protos/query_benchmark/f18.proto similarity index 100% rename from query_benchmark/protos/f18.proto rename to benchmarks/protos/query_benchmark/f18.proto diff --git a/query_benchmark/protos/f19.proto b/benchmarks/protos/query_benchmark/f19.proto similarity index 100% rename from query_benchmark/protos/f19.proto rename to benchmarks/protos/query_benchmark/f19.proto diff --git a/query_benchmark/protos/f2.proto b/benchmarks/protos/query_benchmark/f2.proto similarity index 100% rename from query_benchmark/protos/f2.proto rename to benchmarks/protos/query_benchmark/f2.proto diff --git a/query_benchmark/protos/f20.proto b/benchmarks/protos/query_benchmark/f20.proto similarity index 100% rename from query_benchmark/protos/f20.proto rename to benchmarks/protos/query_benchmark/f20.proto diff --git a/query_benchmark/protos/f21.proto b/benchmarks/protos/query_benchmark/f21.proto similarity index 100% rename from query_benchmark/protos/f21.proto rename to benchmarks/protos/query_benchmark/f21.proto diff --git a/query_benchmark/protos/f22.proto b/benchmarks/protos/query_benchmark/f22.proto similarity index 100% rename from query_benchmark/protos/f22.proto rename to benchmarks/protos/query_benchmark/f22.proto diff --git a/query_benchmark/protos/f23.proto b/benchmarks/protos/query_benchmark/f23.proto similarity index 100% rename from query_benchmark/protos/f23.proto rename to benchmarks/protos/query_benchmark/f23.proto diff --git a/query_benchmark/protos/f24.proto b/benchmarks/protos/query_benchmark/f24.proto similarity index 100% rename from query_benchmark/protos/f24.proto rename to benchmarks/protos/query_benchmark/f24.proto diff --git a/query_benchmark/protos/f25.proto b/benchmarks/protos/query_benchmark/f25.proto similarity index 100% rename from query_benchmark/protos/f25.proto rename to benchmarks/protos/query_benchmark/f25.proto diff --git a/query_benchmark/protos/f26.proto b/benchmarks/protos/query_benchmark/f26.proto similarity index 100% rename from query_benchmark/protos/f26.proto rename to benchmarks/protos/query_benchmark/f26.proto diff --git a/query_benchmark/protos/f27.proto b/benchmarks/protos/query_benchmark/f27.proto similarity index 100% rename from query_benchmark/protos/f27.proto rename to benchmarks/protos/query_benchmark/f27.proto diff --git a/query_benchmark/protos/f28.proto b/benchmarks/protos/query_benchmark/f28.proto similarity index 100% rename from query_benchmark/protos/f28.proto rename to benchmarks/protos/query_benchmark/f28.proto diff --git a/query_benchmark/protos/f3.proto b/benchmarks/protos/query_benchmark/f3.proto similarity index 100% rename from query_benchmark/protos/f3.proto rename to benchmarks/protos/query_benchmark/f3.proto diff --git a/query_benchmark/protos/f4.proto b/benchmarks/protos/query_benchmark/f4.proto similarity index 100% rename from query_benchmark/protos/f4.proto rename to benchmarks/protos/query_benchmark/f4.proto diff --git a/query_benchmark/protos/f5.proto b/benchmarks/protos/query_benchmark/f5.proto similarity index 100% rename from query_benchmark/protos/f5.proto rename to benchmarks/protos/query_benchmark/f5.proto diff --git a/query_benchmark/protos/f6.proto b/benchmarks/protos/query_benchmark/f6.proto similarity index 100% rename from query_benchmark/protos/f6.proto rename to benchmarks/protos/query_benchmark/f6.proto diff --git a/query_benchmark/protos/f7.proto b/benchmarks/protos/query_benchmark/f7.proto similarity index 100% rename from query_benchmark/protos/f7.proto rename to benchmarks/protos/query_benchmark/f7.proto diff --git a/query_benchmark/protos/f8.proto b/benchmarks/protos/query_benchmark/f8.proto similarity index 100% rename from query_benchmark/protos/f8.proto rename to benchmarks/protos/query_benchmark/f8.proto diff --git a/query_benchmark/protos/f9.proto b/benchmarks/protos/query_benchmark/f9.proto similarity index 100% rename from query_benchmark/protos/f9.proto rename to benchmarks/protos/query_benchmark/f9.proto diff --git a/benchmarks/pubspec.lock b/benchmarks/pubspec.lock new file mode 100644 index 000000000..edee7a39b --- /dev/null +++ b/benchmarks/pubspec.lock @@ -0,0 +1,201 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "40.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" + args: + dependency: "direct dev" + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + benchmark_harness: + dependency: "direct dev" + description: + name: benchmark_harness + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + js: + dependency: "direct dev" + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + lints: + dependency: "direct dev" + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + path: + dependency: "direct dev" + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + pool: + dependency: "direct dev" + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.1" + protobuf: + dependency: "direct dev" + description: + path: "../protobuf" + relative: true + source: path + version: "3.0.0-dev" + protoc_plugin: + dependency: "direct dev" + description: + path: "../protoc_plugin" + relative: true + source: path + version: "21.0.0-dev" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" +sdks: + dart: ">=2.16.0-100.0.dev <3.0.0" diff --git a/protobuf_benchmarks/pubspec.yaml b/benchmarks/pubspec.yaml similarity index 79% rename from protobuf_benchmarks/pubspec.yaml rename to benchmarks/pubspec.yaml index 9e49b8d2d..8e1345924 100644 --- a/protobuf_benchmarks/pubspec.yaml +++ b/benchmarks/pubspec.yaml @@ -9,15 +9,18 @@ publish_to: none environment: sdk: '>=2.12.0 <3.0.0' -dependencies: - protobuf: any - dev_dependencies: + args: ^2.3.1 + # NB. When bumping benchmark_harness check if `benchmark_base.BenchmarkBase` + # needs updating benchmark_harness: ^2.0.0 js: ^0.6.3 lints: ^1.0.0 + path: ^1.8.2 + pool: ^1.5.1 protoc_plugin: path: '../protoc_plugin' + protobuf: any dependency_overrides: protobuf: diff --git a/benchmarks/tool/compile_benchmarks.dart b/benchmarks/tool/compile_benchmarks.dart new file mode 100755 index 000000000..6e60f995d --- /dev/null +++ b/benchmarks/tool/compile_benchmarks.dart @@ -0,0 +1,188 @@ +#!/usr/bin/env dart + +import 'dart:io' show exit, Platform, Process, Directory, ProcessResult; + +import 'package:args/args.dart' show ArgParser; +import 'package:path/path.dart' as path; +import 'package:pool/pool.dart' show Pool; + +Future main(List args) async { + final argParser = ArgParser() + ..addOption('target', + mandatory: false, defaultsTo: 'aot,exe,jit,js,js-production') + ..addOption('jobs', abbr: 'j', mandatory: false); + + final parsedArgs = argParser.parse(args); + + var jobs = Platform.numberOfProcessors; + if (parsedArgs['jobs'] != null) { + jobs = int.parse(parsedArgs['jobs']!); + } + + final targets = {}; + for (final targetStr in parsedArgs['target'].split(',')) { + switch (targetStr) { + case 'aot': + targets.add(aotTarget); + break; + + case 'exe': + targets.add(exeTarget); + break; + + case 'jit': + targets.add(jitTarget); + break; + + case 'js': + targets.add(jsTarget); + break; + + case 'js-production': + targets.add(jsProductionTarget); + break; + + default: + print( + 'Unsupported target: $targetStr. Supported targets: aot, exe, jit, js, js-production'); + exit(1); + } + } + + // Arg list is immutable, clone it + var sourceFiles = List.from(parsedArgs.rest); + + if (sourceFiles.isEmpty) { + // Compile all files in bin/ + sourceFiles = Directory('bin') + .listSync(recursive: false) + .where((dirFile) => path.extension(dirFile.path) == '.dart') + .map((dirFile) => dirFile.path) + .toList(); + } + + final commands = >[]; + + if (sourceFiles.isNotEmpty && targets.isNotEmpty) { + try { + Directory('out').createSync(recursive: true); + } catch (e) { + print("Error while creating 'out' directory: $e"); + exit(1); + } + } + + for (final sourceFile in sourceFiles) { + for (final target in targets) { + commands.add(target.compileArgs(sourceFile)); + } + } + + final pool = Pool(jobs); + + final stream = pool.forEach, CompileProcess>(commands, + (List command) async { + final commandStr = command.join(' '); + print(commandStr); + final result = await Process.run(command[0], command.sublist(1)); + return CompileProcess(commandStr, result); + }); + + await for (final compileProcess in stream) { + final exitCode = compileProcess.result.exitCode; + if (exitCode != 0) { + print('Process exited with $exitCode'); + print('Command: ${compileProcess.command}'); + print( + 'Process stdout ---------------------------------------------------'); + print(compileProcess.result.stdout); + print( + 'Process stderr ---------------------------------------------------'); + print(compileProcess.result.stderr); + print( + '------------------------------------------------------------------'); + exit(1); + } + } + + await pool.done; +} + +class CompileProcess { + final String command; + final ProcessResult result; + + CompileProcess(this.command, this.result); +} + +class Target { + final String _name; + final List Function(String) _processArgs; + + const Target(this._name, this._processArgs); + + @override + String toString() { + return 'Target($_name)'; + } + + List compileArgs(String sourceFile) { + return _processArgs(sourceFile); + } +} + +const aotTarget = Target('aot', aotProcessArgs); +const exeTarget = Target('exe', exeProcessArgs); +const jitTarget = Target('jit', jitProcessArgs); +const jsTarget = Target('js', jsProcessArgs); +const jsProductionTarget = Target('js-production', jsProductionProcessArgs); + +List aotProcessArgs(String sourceFile) { + final baseName = path.basename(sourceFile); + final baseNameNoExt = path.withoutExtension(baseName); + return [ + 'dart', + 'compile', + 'aot-snapshot', + sourceFile, + '-o', + 'out/$baseNameNoExt.aot' + ]; +} + +List exeProcessArgs(String sourceFile) { + final baseName = path.basename(sourceFile); + final baseNameNoExt = path.withoutExtension(baseName); + return ['dart', 'compile', 'exe', sourceFile, '-o', 'out/$baseNameNoExt.exe']; +} + +List jitProcessArgs(String sourceFile) { + final baseName = path.basename(sourceFile); + final baseNameNoExt = path.withoutExtension(baseName); + return [ + 'dart', + '--snapshot-kind=kernel', + '--snapshot=out/$baseNameNoExt.dill', + sourceFile + ]; +} + +List jsProcessArgs(String sourceFile) { + final baseName = path.basename(sourceFile); + final baseNameNoExt = path.withoutExtension(baseName); + return ['dart', 'compile', 'js', sourceFile, '-o', 'out/$baseNameNoExt.js']; +} + +List jsProductionProcessArgs(String sourceFile) { + final baseName = path.basename(sourceFile); + final baseNameNoExt = path.withoutExtension(baseName); + return [ + 'dart', + 'compile', + 'js', + sourceFile, + '-O4', + '-o', + 'out/$baseNameNoExt.production.js' + ]; +} diff --git a/benchmarks/tool/compile_protos.sh b/benchmarks/tool/compile_protos.sh new file mode 100755 index 000000000..5fd12b833 --- /dev/null +++ b/benchmarks/tool/compile_protos.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright (c) 2022, 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. + +SCRIPT_DIR=$(dirname "${BASH_SOURCE}") +BENCHMARK_DIR=$SCRIPT_DIR/.. + +# These protos don't have any imports +SIMPLE_PROTOS=( + "protos/google_message1_proto2.proto" + "protos/google_message1_proto3.proto" + "protos/google_message2.proto" +) + +set -x +set -e + +mkdir -p lib/generated + +protoc --dart_out=lib/generated --plugin=protoc-gen-dart=tool/run_protoc_plugin.sh \ + -I$BENCHMARK_DIR/protos \ + "${SIMPLE_PROTOS[@]/#/$BENCHMARK_DIR/}" + +protoc --dart_out=lib/generated --plugin=protoc-gen-dart=tool/run_protoc_plugin.sh \ + -I$BENCHMARK_DIR/protos/query_benchmark \ + $BENCHMARK_DIR/protos/query_benchmark/*.proto + +dart format lib/generated diff --git a/benchmarks/tool/run_protoc_plugin.sh b/benchmarks/tool/run_protoc_plugin.sh new file mode 100755 index 000000000..e32cf9880 --- /dev/null +++ b/benchmarks/tool/run_protoc_plugin.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Copyright (c) 2022, 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 run protoc_plugin protoc-gen-dart diff --git a/protobuf_benchmarks/.gitignore b/protobuf_benchmarks/.gitignore deleted file mode 100644 index 9c595a6fb..000000000 --- a/protobuf_benchmarks/.gitignore +++ /dev/null @@ -1 +0,0 @@ -temp diff --git a/protobuf_benchmarks/README.md b/protobuf_benchmarks/README.md deleted file mode 100644 index 6f93fc979..000000000 --- a/protobuf_benchmarks/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Protobuf Benchmarks - -This directory contains protobuf benchmarks adapted from [original protobuf]( -https://github.com/google/protobuf/tree/master/benchmarks) library. - -These benchmarks cover parsing and serializing protobufs both to binary and -JSON formats, and hash code generation for messages. - -## Prerequisites - -Before running benchmarks you first need to compile all involved protos, which -requires installing `protoc` and [protoc_plugin](../../protoc_plugin). - -```console -$ ./compile_protos.sh -``` - -This compiles test protos to Dart. - -## Running benchmarks on the VM - -``` -$ dart bin/benchmark_vm.dart -``` - -## Running benchmarks via JavaScript (D8) - -``` -$ ./compile_js.sh -$ d8 $DART_SDK/lib/_internal/js_runtime/lib/preambles/d8.js bin/benchmark.js -``` - -Note: if you are seeing a "Error reading file" error while running the JS -benchmarks it means that you are in the wrong directory. Run the `d8` command -shown above in `protobuf_benchmarks/` directory. diff --git a/protobuf_benchmarks/benchmarks.proto b/protobuf_benchmarks/benchmarks.proto deleted file mode 100644 index 51c0b5487..000000000 --- a/protobuf_benchmarks/benchmarks.proto +++ /dev/null @@ -1,63 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; -package benchmarks; -option java_package = "com.google.protobuf.benchmarks"; - -message BenchmarkDataset { - // Name of the benchmark dataset. This should be unique across all datasets. - // Should only contain word characters: [a-zA-Z0-9_] - string name = 1; - - // Fully-qualified name of the protobuf message for this dataset. - // It will be one of the messages defined benchmark_messages_proto2.proto - // or benchmark_messages_proto3.proto. - // - // Implementations that do not support reflection can implement this with - // an explicit "if/else" chain that lists every known message defined - // in those files. - string message_name = 2; - - // The payload(s) for this dataset. They should be parsed or serialized - // in sequence, in a loop, ie. - // - // while (!benchmarkDone) { // Benchmark runner decides when to exit. - // for (i = 0; i < benchmark.payload.length; i++) { - // parse(benchmark.payload[i]) - // } - // } - // - // This is intended to let datasets include a variety of data to provide - // potentially more realistic results than just parsing the same message - // over and over. A single message parsed repeatedly could yield unusually - // good branch prediction performance. - repeated bytes payload = 3; -} diff --git a/protobuf_benchmarks/bin/basic_benchmarks.dart b/protobuf_benchmarks/bin/basic_benchmarks.dart deleted file mode 100644 index a567ea985..000000000 --- a/protobuf_benchmarks/bin/basic_benchmarks.dart +++ /dev/null @@ -1,14 +0,0 @@ -// 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:protobuf_benchmarks/common.dart'; -import 'package:protobuf_benchmarks/readfile.dart'; - -void main() { - final datasets = datasetFiles - .map((file) => Dataset.fromBinary(readfile(file))) - .toList(growable: false); - - run(datasets); -} diff --git a/protobuf_benchmarks/compile_js.sh b/protobuf_benchmarks/compile_js.sh deleted file mode 100755 index 977b0bab3..000000000 --- a/protobuf_benchmarks/compile_js.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -# 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. - -# Compile benchmark_js to JavaScript using dart2js. - -SCRIPT_DIR=$(dirname "${BASH_SOURCE}") - -dart compile js \ - -O4 \ - -o "${SCRIPT_DIR}"/bin/benchmark.js \ - "${SCRIPT_DIR}"/bin/benchmark_js.dart diff --git a/protobuf_benchmarks/compile_protos.sh b/protobuf_benchmarks/compile_protos.sh deleted file mode 100755 index ff160aefa..000000000 --- a/protobuf_benchmarks/compile_protos.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# 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. - -# Compile all protos involed in the benchmarking using protoc compiler. - -PROTOS=( - "benchmarks.proto" - "datasets/google_message1/proto2/benchmark_message1_proto2.proto" - "datasets/google_message1/proto3/benchmark_message1_proto3.proto" - "datasets/google_message2/benchmark_message2.proto" -) - -SCRIPT_DIR=$(dirname "${BASH_SOURCE}") - -set -x - -mkdir -p lib/generated - -protoc -I"${SCRIPT_DIR}" --dart_out=lib/generated --plugin=protoc-gen-dart=run_protoc_plugin.sh "${PROTOS[@]/#/$SCRIPT_DIR/}" diff --git a/protobuf_benchmarks/d8.dart b/protobuf_benchmarks/d8.dart deleted file mode 100644 index f55ef7073..000000000 --- a/protobuf_benchmarks/d8.dart +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -/// Wrapper over d8 specific helper methods. -@JS() -library d8; - -import 'dart:typed_data'; - -import 'package:js/js.dart'; - -/// Read the file at the given [path] and return its contents in -/// an [ByteBuffer]. -@JS() -external ByteBuffer readbuffer(String path); - -/// Read the [file] and return its contents in -/// a Uint8List. -Uint8List readAsBytesSync(String file) { - return Uint8List.view(readbuffer(file)); -} diff --git a/protobuf_benchmarks/lib/common.dart b/protobuf_benchmarks/lib/common.dart deleted file mode 100644 index 50c3f7452..000000000 --- a/protobuf_benchmarks/lib/common.dart +++ /dev/null @@ -1,281 +0,0 @@ -// 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. - -// ignore_for_file: uri_has_not_been_generated,undefined_identifier - -/// Common platform independent benchmark infrastructure that can run -/// both on the VM and when compiled to JavaScript. -library common; - -import 'dart:convert' show jsonDecode, jsonEncode; -import 'dart:typed_data'; - -import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:protobuf/protobuf.dart'; - -import 'generated/benchmarks.pb.dart'; -import 'generated/datasets/google_message1/proto2/benchmark_message1_proto2.pb.dart' - as p2; -import 'generated/datasets/google_message1/proto3/benchmark_message1_proto3.pb.dart' - as p3; -import 'generated/datasets/google_message2/benchmark_message2.pb.dart'; - -const datasetsDir = - const String.fromEnvironment('datasets_dir', defaultValue: 'datasets'); - -final datasetFiles = [ - '$datasetsDir/google_message1/proto3/dataset.google_message1_proto3.pb', - '$datasetsDir/google_message1/proto2/dataset.google_message1_proto2.pb', - '$datasetsDir/google_message2/dataset.google_message2.pb' -]; - -/// Represents a dataset, a list of protobufs payloads, used for benchmarking. -/// All payloads are instances of the same message. -/// Datasets are loaded from BenchmarkDataset proto (see benchmark.proto). -class Dataset { - final String name; - - /// Functions that can deserialize all payloads in this dataset. - final Factories factories; - - /// List of packed payloads, which can be deserialized using [factories]. - final List packed = []; - - /// Messages deserialized from [packed] and then serialized back into JSON. - /// Used for JSON serialization benchmarks. - final List asJson = []; - - /// Messages deserialized from [packed] and then serialized back into proto3 - /// JSON object. Used for proto3 JSON serialization benchmarks. - final List asProto3JsonObject = []; - - /// Messages deserialized from [packed] and then serialized back into proto3 - /// JSON string. Used for proto3 JSON serialization benchmarks. - final List asProto3JsonString = []; - - /// Messages deserialized from [packed]. Used in serialization benchmarks. - final List unpacked = []; - - /// Create [Dataset] from a `BenchmarkDataset` proto. - factory Dataset.fromBinary(Uint8List binary) { - final dataSet = BenchmarkDataset.fromBuffer(binary); - - final factories = Factories.forMessage(dataSet.messageName); - final ds = Dataset._(dataSet.name, factories); - - for (var payload in dataSet.payload) { - final bytes = Uint8List.fromList(payload); - final msg = factories.fromBuffer(bytes); - ds.packed.add(bytes); - ds.unpacked.add(msg); - ds.asJson.add(msg.writeToJson()); - final proto3Json = msg.toProto3Json(); - ds.asProto3JsonObject.add(proto3Json); - ds.asProto3JsonString.add(jsonEncode(proto3Json)); - } - - return ds; - } - - Dataset._(this.name, this.factories); -} - -typedef FromBufferFactory = dynamic Function(List binary); -typedef FromJsonFactory = dynamic Function(String json); -typedef FromProto3JsonStringFactory = dynamic Function(String json); -typedef FromProto3JsonObjectFactory = dynamic Function(Object json); - -class Factories { - final FromBufferFactory fromBuffer; - final FromJsonFactory fromJson; - final FromProto3JsonStringFactory fromProto3JsonString; - final FromProto3JsonObjectFactory fromProto3JsonObject; - - static Factories forMessage(String name) => - _factories[name] ?? (throw 'Unsupported message: $name'); - - /// Mapping between `BenchmarkDataset.messageName` and corresponding - /// deserialization factories. - static final _factories = { - 'benchmarks.proto2.GoogleMessage1': Factories._( - fromBuffer: (List binary) => p2.GoogleMessage1.fromBuffer(binary), - fromJson: (String json) => p2.GoogleMessage1.fromJson(json), - fromProto3JsonString: (String json) => - p2.GoogleMessage1.create()..mergeFromProto3Json(jsonDecode(json)), - fromProto3JsonObject: (Object json) => - p2.GoogleMessage1.create()..mergeFromProto3Json(json)), - 'benchmarks.proto3.GoogleMessage1': Factories._( - fromBuffer: (List binary) => p3.GoogleMessage1.fromBuffer(binary), - fromJson: (String json) => p3.GoogleMessage1.fromJson(json), - fromProto3JsonString: (String json) => - p3.GoogleMessage1.create()..mergeFromProto3Json(jsonDecode(json)), - fromProto3JsonObject: (Object json) => - p3.GoogleMessage1.create()..mergeFromProto3Json(json)), - 'benchmarks.proto2.GoogleMessage2': Factories._( - fromBuffer: (List binary) => GoogleMessage2.fromBuffer(binary), - fromJson: (String json) => GoogleMessage2.fromJson(json), - fromProto3JsonString: (String json) => - GoogleMessage2.create()..mergeFromProto3Json(jsonDecode(json)), - fromProto3JsonObject: (Object json) => - GoogleMessage2.create()..mergeFromProto3Json(json)), - }; - - Factories._( - {required this.fromBuffer, - required this.fromJson, - required this.fromProto3JsonString, - required this.fromProto3JsonObject}); -} - -/// Base for all protobuf benchmarks. -abstract class _ProtobufBenchmark extends BenchmarkBase { - final List datasets; - - _ProtobufBenchmark(this.datasets, String name) : super(name); -} - -/// Binary deserialization benchmark. -class FromBinaryBenchmark extends _ProtobufBenchmark { - FromBinaryBenchmark(datasets) : super(datasets, 'FromBinary'); - - @override - void run() { - for (var i = 0; i < datasets.length; i++) { - final ds = datasets[i]; - final f = ds.factories.fromBuffer; - for (var j = 0; j < ds.packed.length; j++) { - f(ds.packed[j]); - } - } - } -} - -/// Binary serialization benchmark. -class ToBinaryBenchmark extends _ProtobufBenchmark { - ToBinaryBenchmark(datasets) : super(datasets, 'ToBinary'); - - @override - void run() { - for (final ds in datasets) { - for (final unpacked in ds.unpacked) { - unpacked.writeToBuffer(); - } - } - } -} - -/// JSON deserialization benchmark. -class FromJsonBenchmark extends _ProtobufBenchmark { - FromJsonBenchmark(datasets) : super(datasets, 'FromJson'); - - @override - void run() { - for (final ds in datasets) { - final f = ds.factories.fromJson; - for (final jsonStr in ds.asJson) { - f(jsonStr); - } - } - } -} - -/// JSON serialization benchmark. -class ToJsonBenchmark extends _ProtobufBenchmark { - ToJsonBenchmark(datasets) : super(datasets, 'ToJson'); - - @override - void run() { - for (final ds in datasets) { - for (final unpacked in ds.unpacked) { - unpacked.writeToJson(); - } - } - } -} - -/// proto3 JSON deserialization benchmark: from JSON string to message. -class FromProto3JsonStringBenchmark extends _ProtobufBenchmark { - FromProto3JsonStringBenchmark(datasets) - : super(datasets, 'FromProto3JsonString'); - - @override - void run() { - for (final ds in datasets) { - final f = ds.factories.fromProto3JsonString; - for (final jsonStr in ds.asProto3JsonString) { - f(jsonStr); - } - } - } -} - -/// proto3 JSON serialization benchmark: from message to JSON string. -class ToProto3JsonStringBenchmark extends _ProtobufBenchmark { - ToProto3JsonStringBenchmark(datasets) : super(datasets, 'ToProto3JsonString'); - - @override - void run() { - for (final ds in datasets) { - for (final unpacked in ds.unpacked) { - jsonEncode(unpacked.toProto3Json()); - } - } - } -} - -/// proto3 JSON deserialization benchmark: from JSON object to message. -class FromProto3JsonObjectBenchmark extends _ProtobufBenchmark { - FromProto3JsonObjectBenchmark(datasets) - : super(datasets, 'FromProto3JsonObject'); - - @override - void run() { - for (final ds in datasets) { - final f = ds.factories.fromProto3JsonObject; - for (final jsonObj in ds.asProto3JsonObject) { - f(jsonObj); - } - } - } -} - -/// proto3 JSON serialization benchmark: from message to JSON object. -class ToProto3JsonObjectBenchmark extends _ProtobufBenchmark { - ToProto3JsonObjectBenchmark(datasets) : super(datasets, 'ToProto3JsonObject'); - - @override - void run() { - for (final ds in datasets) { - for (final unpacked in ds.unpacked) { - unpacked.toProto3Json(); - } - } - } -} - -/// HashCode computation benchmark. -class HashCodeBenchmark extends _ProtobufBenchmark { - HashCodeBenchmark(datasets) : super(datasets, 'HashCode'); - - @override - void run() { - for (final dataset in datasets) { - for (final unpacked in dataset.unpacked) { - unpacked.hashCode; - } - } - } -} - -void run(List datasets) { - FromBinaryBenchmark(datasets).report(); - ToBinaryBenchmark(datasets).report(); - FromJsonBenchmark(datasets).report(); - ToJsonBenchmark(datasets).report(); - FromProto3JsonStringBenchmark(datasets).report(); - ToProto3JsonStringBenchmark(datasets).report(); - FromProto3JsonObjectBenchmark(datasets).report(); - ToProto3JsonObjectBenchmark(datasets).report(); - HashCodeBenchmark(datasets).report(); -} diff --git a/protobuf_benchmarks/run_protoc_plugin.sh b/protobuf_benchmarks/run_protoc_plugin.sh deleted file mode 100755 index 958631717..000000000 --- a/protobuf_benchmarks/run_protoc_plugin.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -dart run protoc_plugin protoc-gen-dart diff --git a/query_benchmark/analysis_options.yaml b/query_benchmark/analysis_options.yaml deleted file mode 100644 index e84124713..000000000 --- a/query_benchmark/analysis_options.yaml +++ /dev/null @@ -1,9 +0,0 @@ -include: package:lints/recommended.yaml - -linter: - rules: - - comment_references - - directives_ordering - - prefer_relative_imports - - prefer_single_quotes - - prefer_spread_collections diff --git a/query_benchmark/bin/decode.dart b/query_benchmark/bin/decode.dart deleted file mode 100644 index f83e88967..000000000 --- a/query_benchmark/bin/decode.dart +++ /dev/null @@ -1,20 +0,0 @@ -// 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/benchmark.dart'; -import 'package:query_benchmark/generated/f0.pb.dart' as f0; -import 'package:query_benchmark/readfile.dart'; - -main() { - final path = - const String.fromEnvironment('testfile', defaultValue: 'testdata/500.pb'); - - List encoded = readfile(path); - print( - formatReport( - title: 'protobuf_decode', - duration: measure(() => f0.A0.fromBuffer(encoded)), - ), - ); -} diff --git a/query_benchmark/bin/decode_json.dart b/query_benchmark/bin/decode_json.dart deleted file mode 100644 index da0fe6fbb..000000000 --- a/query_benchmark/bin/decode_json.dart +++ /dev/null @@ -1,22 +0,0 @@ -// 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/benchmark.dart'; -import 'package:query_benchmark/generated/f0.pb.dart' as f0; -import 'package:query_benchmark/readfile.dart'; - -main() { - final path = - const String.fromEnvironment('testfile', defaultValue: 'testdata/500.pb'); - - List 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)), - ), - ); -} diff --git a/query_benchmark/bin/encode.dart b/query_benchmark/bin/encode.dart deleted file mode 100644 index 5f9380697..000000000 --- a/query_benchmark/bin/encode.dart +++ /dev/null @@ -1,21 +0,0 @@ -// 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/benchmark.dart'; -import 'package:query_benchmark/generated/f0.pb.dart' as f0; -import 'package:query_benchmark/readfile.dart'; - -main() { - final path = - const String.fromEnvironment('testfile', defaultValue: 'testdata/500.pb'); - - List encoded = readfile(path); - f0.A0 a = f0.A0.fromBuffer(encoded); - print( - formatReport( - title: 'protobuf_encode', - duration: measure(() => a.writeToBuffer()), - ), - ); -} diff --git a/query_benchmark/bin/encode_json.dart b/query_benchmark/bin/encode_json.dart deleted file mode 100644 index 41f483bcd..000000000 --- a/query_benchmark/bin/encode_json.dart +++ /dev/null @@ -1,21 +0,0 @@ -// 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/benchmark.dart'; -import 'package:query_benchmark/generated/f0.pb.dart' as f0; -import 'package:query_benchmark/readfile.dart'; - -main() { - final path = - const String.fromEnvironment('testfile', defaultValue: 'testdata/500.pb'); - - List encoded = readfile(path); - f0.A0 a = f0.A0.fromBuffer(encoded); - print( - formatReport( - title: 'protobuf_encode_json', - duration: measure(() => a.writeToJson()), - ), - ); -} diff --git a/query_benchmark/bin/set_nested_value.dart b/query_benchmark/bin/set_nested_value.dart deleted file mode 100644 index 0b7afb696..000000000 --- a/query_benchmark/bin/set_nested_value.dart +++ /dev/null @@ -1,29 +0,0 @@ -// 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:protobuf/protobuf.dart'; -import 'package:query_benchmark/benchmark.dart'; -import 'package:query_benchmark/generated/f0.pb.dart' as f0; -import 'package:query_benchmark/generated/f19.pb.dart' as f19; -import 'package:query_benchmark/generated/f2.pb.dart' as f2; -import 'package:query_benchmark/readfile.dart'; - -main() { - final path = - const String.fromEnvironment('testfile', defaultValue: 'testdata/500.pb'); - - List encoded = readfile(path); - f0.A0 a = f0.A0.fromBuffer(encoded)..freeze(); - print( - formatReport( - title: 'protobuf_decode', - duration: measure(() => a.rebuild((f0.A0 a0Builder) { - a0Builder.a4.last = a0Builder.a4.last.rebuild((f2.A1 a1builder) { - a1builder.a378 = a1builder.a378.rebuild( - (f19.A220 a220builder) => a220builder.a234 = 'new_value'); - }); - })), - ), - ); -} diff --git a/query_benchmark/compile_protos.sh b/query_benchmark/compile_protos.sh deleted file mode 100755 index 03b69d8bb..000000000 --- a/query_benchmark/compile_protos.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/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 -dart format lib/generated diff --git a/query_benchmark/lib/benchmark.dart b/query_benchmark/lib/benchmark.dart deleted file mode 100644 index d69419443..000000000 --- a/query_benchmark/lib/benchmark.dart +++ /dev/null @@ -1,22 +0,0 @@ -// 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({required String title, required Duration duration}) { - return 'RunTimeRaw($title): ${duration.inMicroseconds} us'; -} diff --git a/query_benchmark/lib/readfile.dart b/query_benchmark/lib/readfile.dart deleted file mode 100644 index b4614ea79..000000000 --- a/query_benchmark/lib/readfile.dart +++ /dev/null @@ -1,5 +0,0 @@ -// 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; diff --git a/query_benchmark/lib/readfile_d8.dart b/query_benchmark/lib/readfile_d8.dart deleted file mode 100644 index 990511187..000000000 --- a/query_benchmark/lib/readfile_d8.dart +++ /dev/null @@ -1,18 +0,0 @@ -// 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:typed_data'; - -import 'package:js/js.dart'; - -/// Read the file at the given [path]. -/// -/// This relies on the `readbuffer` function provided by d8. -@JS() -external ByteBuffer readbuffer(String path); - -/// Read the file at the given [path]. -Uint8List readfile(String path) { - return Uint8List.view(readbuffer(path)); -} diff --git a/query_benchmark/lib/readfile_vm.dart b/query_benchmark/lib/readfile_vm.dart deleted file mode 100644 index e202ec980..000000000 --- a/query_benchmark/lib/readfile_vm.dart +++ /dev/null @@ -1,9 +0,0 @@ -// 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 readfile(String path) { - return File(path).readAsBytesSync(); -} diff --git a/query_benchmark/protoc_version b/query_benchmark/protoc_version deleted file mode 100644 index 12566ed7f..000000000 --- a/query_benchmark/protoc_version +++ /dev/null @@ -1 +0,0 @@ -3.14.0 \ No newline at end of file diff --git a/query_benchmark/pubspec.yaml b/query_benchmark/pubspec.yaml deleted file mode 100644 index b4b5bd4f7..000000000 --- a/query_benchmark/pubspec.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2022, 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. - -name: query_benchmark -description: Measuring encoding and decoding of a "real-world" protobuf. - -# This package is not intended for consumption on pub.dev. DO NOT publish. -publish_to: none - -environment: - sdk: '>=2.12.0 <3.0.0' - -dependencies: - protobuf: any - -dev_dependencies: - js: ^0.6.3 - lints: ^1.0.0 - protoc_plugin: - path: "../protoc_plugin" - -dependency_overrides: - protobuf: - path: "../protobuf" diff --git a/query_benchmark/run_protoc_plugin.sh b/query_benchmark/run_protoc_plugin.sh deleted file mode 100755 index 958631717..000000000 --- a/query_benchmark/run_protoc_plugin.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -dart run protoc_plugin protoc-gen-dart diff --git a/tool/ci.sh b/tool/ci.sh index 3251acc7a..2ee2c18c4 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -88,6 +88,10 @@ for PKG in ${PKGS}; do ./compile_protos.sh || EXIT_CODE=$? ;; command_2) + echo './tool/compile_protos.sh' + ./tool/compile_protos.sh || EXIT_CODE=$? + ;; + command_3) echo 'make protos' make protos || EXIT_CODE=$? ;;