From d5001a93d056fb3f52525543652ef5e8de46c0b5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 1 Feb 2024 13:43:20 +0100 Subject: [PATCH] Add a dedicated benchmark for protos with long repeated fields. --- benchmarks/bin/repeated_field.dart | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 benchmarks/bin/repeated_field.dart diff --git a/benchmarks/bin/repeated_field.dart b/benchmarks/bin/repeated_field.dart new file mode 100644 index 000000000..16c1b1780 --- /dev/null +++ b/benchmarks/bin/repeated_field.dart @@ -0,0 +1,45 @@ +import 'dart:typed_data'; + +import 'package:fixnum/fixnum.dart'; +import 'package:protobuf_benchmarks/benchmark_base.dart'; +import 'package:protobuf_benchmarks/generated/f12.pb.dart' as f12; +import 'package:protobuf_benchmarks/generated/google_message2.pb.dart'; + +class RepeatedBenchmark extends BenchmarkBase { + final Uint8List _buffer; + + RepeatedBenchmark(super.name, GoogleMessage2 message) + : _buffer = message.writeToBuffer(); + + @override + void run() => GoogleMessage2.fromBuffer(_buffer); +} + +class RepeatedEnumBenchmark extends BenchmarkBase { + final Uint8List _buffer; + + RepeatedEnumBenchmark(super.name, f12.A58 message) + : _buffer = message.writeToBuffer(); + + @override + void run() => f12.A58.fromBuffer(_buffer); +} + +void main() { + const kSize = 500000; + + RepeatedBenchmark( + 'repeated_int64', + GoogleMessage2(field130: List.generate(kSize, Int64.new)), + ).report(); + + RepeatedBenchmark( + 'repeated_string', + GoogleMessage2(field128: List.generate(kSize, (i) => i.toString())), + ).report(); + + RepeatedEnumBenchmark( + 'repeated_enum', + f12.A58(a306: List.generate(kSize, (_) => f12.A322.A324)), + ).report(); +}