xref: /third_party/protobuf/benchmarks/README.md (revision ffe3c632)
1ffe3c632Sopenharmony_ci
2ffe3c632Sopenharmony_ci# Protocol Buffers Benchmarks
3ffe3c632Sopenharmony_ci
4ffe3c632Sopenharmony_ciThis directory contains benchmarking schemas and data sets that you
5ffe3c632Sopenharmony_cican use to test a variety of performance scenarios against your
6ffe3c632Sopenharmony_ciprotobuf language runtime. If you are looking for performance
7ffe3c632Sopenharmony_cinumbers of officially support languages, see [here](
8ffe3c632Sopenharmony_cihttps://github.com/protocolbuffers/protobuf/blob/master/docs/performance.md)
9ffe3c632Sopenharmony_ci
10ffe3c632Sopenharmony_ci## Prerequisite
11ffe3c632Sopenharmony_ci
12ffe3c632Sopenharmony_ciFirst, you need to follow the instruction in the root directory's README to
13ffe3c632Sopenharmony_cibuild your language's protobuf, then:
14ffe3c632Sopenharmony_ci
15ffe3c632Sopenharmony_ci### CPP
16ffe3c632Sopenharmony_ciYou need to install [cmake](https://cmake.org/) before building the benchmark.
17ffe3c632Sopenharmony_ci
18ffe3c632Sopenharmony_ciWe are using [google/benchmark](https://github.com/google/benchmark) as the
19ffe3c632Sopenharmony_cibenchmark tool for testing cpp. This will be automatically made during build the
20ffe3c632Sopenharmony_cicpp benchmark.
21ffe3c632Sopenharmony_ci
22ffe3c632Sopenharmony_ciThe cpp protobuf performance can be improved by linking with [tcmalloc library](
23ffe3c632Sopenharmony_cihttps://gperftools.github.io/gperftools/tcmalloc.html). For using tcmalloc, you
24ffe3c632Sopenharmony_cineed to build [gpertools](https://github.com/gperftools/gperftools) to generate
25ffe3c632Sopenharmony_cilibtcmallc.so library.
26ffe3c632Sopenharmony_ci
27ffe3c632Sopenharmony_ci### Java
28ffe3c632Sopenharmony_ciWe're using maven to build the java benchmarks, which is the same as to build
29ffe3c632Sopenharmony_cithe Java protobuf. There're no other tools need to install. We're using
30ffe3c632Sopenharmony_ci[google/caliper](https://github.com/google/caliper) as benchmark tool, which
31ffe3c632Sopenharmony_cican be automatically included by maven.
32ffe3c632Sopenharmony_ci
33ffe3c632Sopenharmony_ci### Python
34ffe3c632Sopenharmony_ciWe're using python C++ API for testing the generated
35ffe3c632Sopenharmony_ciCPP proto version of python protobuf, which is also a prerequisite for Python
36ffe3c632Sopenharmony_ciprotobuf cpp implementation. You need to install the correct version of Python
37ffe3c632Sopenharmony_ciC++ extension package before run generated CPP proto version of Python
38ffe3c632Sopenharmony_ciprotobuf's benchmark. e.g. under Ubuntu, you need to
39ffe3c632Sopenharmony_ci
40ffe3c632Sopenharmony_ci```
41ffe3c632Sopenharmony_ci$ sudo apt-get install python-dev
42ffe3c632Sopenharmony_ci$ sudo apt-get install python3-dev
43ffe3c632Sopenharmony_ci```
44ffe3c632Sopenharmony_ciAnd you also need to make sure `pkg-config` is installed.
45ffe3c632Sopenharmony_ci
46ffe3c632Sopenharmony_ci### Go
47ffe3c632Sopenharmony_ciGo protobufs are maintained at [github.com/golang/protobuf](
48ffe3c632Sopenharmony_cihttp://github.com/golang/protobuf). If not done already, you need to install the
49ffe3c632Sopenharmony_citoolchain and the Go protoc-gen-go plugin for protoc.
50ffe3c632Sopenharmony_ci
51ffe3c632Sopenharmony_ciTo install protoc-gen-go, run:
52ffe3c632Sopenharmony_ci
53ffe3c632Sopenharmony_ci```
54ffe3c632Sopenharmony_ci$ go get -u github.com/golang/protobuf/protoc-gen-go
55ffe3c632Sopenharmony_ci$ export PATH=$PATH:$(go env GOPATH)/bin
56ffe3c632Sopenharmony_ci```
57ffe3c632Sopenharmony_ci
58ffe3c632Sopenharmony_ciThe first command installs `protoc-gen-go` into the `bin` directory in your local `GOPATH`.
59ffe3c632Sopenharmony_ciThe second command adds the `bin` directory to your `PATH` so that `protoc` can locate the plugin later.
60ffe3c632Sopenharmony_ci
61ffe3c632Sopenharmony_ci### PHP
62ffe3c632Sopenharmony_ciPHP benchmark's requirement is the same as PHP protobuf's requirements. The benchmark will automatically
63ffe3c632Sopenharmony_ciinclude PHP protobuf's src and build the c extension if required.
64ffe3c632Sopenharmony_ci
65ffe3c632Sopenharmony_ci### Node.js
66ffe3c632Sopenharmony_ciNode.js benchmark need [node](https://nodejs.org/en/)(higher than V6) and [npm](https://www.npmjs.com/) package manager installed. This benchmark is using the [benchmark](https://www.npmjs.com/package/benchmark) framework to test, which needn't to manually install. And another prerequisite is [protobuf js](https://github.com/protocolbuffers/protobuf/tree/master/js), which needn't to manually install either
67ffe3c632Sopenharmony_ci
68ffe3c632Sopenharmony_ci### C#
69ffe3c632Sopenharmony_ciThe C# benchmark code is built as part of the main Google.Protobuf
70ffe3c632Sopenharmony_cisolution. It requires the .NET Core SDK, and depends on
71ffe3c632Sopenharmony_ci[BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet), which
72ffe3c632Sopenharmony_ciwill be downloaded automatically.
73ffe3c632Sopenharmony_ci
74ffe3c632Sopenharmony_ci### Big data
75ffe3c632Sopenharmony_ci
76ffe3c632Sopenharmony_ciThere's some optional big testing data which is not included in the directory
77ffe3c632Sopenharmony_ciinitially, you need to run the following command to download the testing data:
78ffe3c632Sopenharmony_ci
79ffe3c632Sopenharmony_ci```
80ffe3c632Sopenharmony_ci$ ./download_data.sh
81ffe3c632Sopenharmony_ci```
82ffe3c632Sopenharmony_ci
83ffe3c632Sopenharmony_ciAfter doing this the big data file will automatically generated in the
84ffe3c632Sopenharmony_cibenchmark directory.
85ffe3c632Sopenharmony_ci
86ffe3c632Sopenharmony_ci## Run instructions
87ffe3c632Sopenharmony_ci
88ffe3c632Sopenharmony_ciTo run all the benchmark dataset:
89ffe3c632Sopenharmony_ci
90ffe3c632Sopenharmony_ci### Java:
91ffe3c632Sopenharmony_ci
92ffe3c632Sopenharmony_ci```
93ffe3c632Sopenharmony_ci$ make java
94ffe3c632Sopenharmony_ci```
95ffe3c632Sopenharmony_ci
96ffe3c632Sopenharmony_ci### CPP:
97ffe3c632Sopenharmony_ci
98ffe3c632Sopenharmony_ci```
99ffe3c632Sopenharmony_ci$ make cpp
100ffe3c632Sopenharmony_ci```
101ffe3c632Sopenharmony_ci
102ffe3c632Sopenharmony_ciFor linking with tcmalloc:
103ffe3c632Sopenharmony_ci
104ffe3c632Sopenharmony_ci```
105ffe3c632Sopenharmony_ci$ env LD_PRELOAD={directory to libtcmalloc.so} make cpp
106ffe3c632Sopenharmony_ci```
107ffe3c632Sopenharmony_ci
108ffe3c632Sopenharmony_ci### Python:
109ffe3c632Sopenharmony_ci
110ffe3c632Sopenharmony_ciWe have three versions of python protobuf implementation: pure python, cpp
111ffe3c632Sopenharmony_cireflection and cpp generated code. To run these version benchmark, you need to:
112ffe3c632Sopenharmony_ci
113ffe3c632Sopenharmony_ci#### Pure Python:
114ffe3c632Sopenharmony_ci
115ffe3c632Sopenharmony_ci```
116ffe3c632Sopenharmony_ci$ make python-pure-python
117ffe3c632Sopenharmony_ci```
118ffe3c632Sopenharmony_ci
119ffe3c632Sopenharmony_ci#### CPP reflection:
120ffe3c632Sopenharmony_ci
121ffe3c632Sopenharmony_ci```
122ffe3c632Sopenharmony_ci$ make python-cpp-reflection
123ffe3c632Sopenharmony_ci```
124ffe3c632Sopenharmony_ci
125ffe3c632Sopenharmony_ci#### CPP generated code:
126ffe3c632Sopenharmony_ci
127ffe3c632Sopenharmony_ci```
128ffe3c632Sopenharmony_ci$ make python-cpp-generated-code
129ffe3c632Sopenharmony_ci```
130ffe3c632Sopenharmony_ci
131ffe3c632Sopenharmony_ci### Go
132ffe3c632Sopenharmony_ci```
133ffe3c632Sopenharmony_ci$ make go
134ffe3c632Sopenharmony_ci```
135ffe3c632Sopenharmony_ci
136ffe3c632Sopenharmony_ci
137ffe3c632Sopenharmony_ci### PHP
138ffe3c632Sopenharmony_ciWe have two version of php protobuf implemention: pure php, php with c extension. To run these version benchmark, you need to:
139ffe3c632Sopenharmony_ci#### Pure PHP
140ffe3c632Sopenharmony_ci```
141ffe3c632Sopenharmony_ci$ make php
142ffe3c632Sopenharmony_ci```
143ffe3c632Sopenharmony_ci#### PHP with c extension
144ffe3c632Sopenharmony_ci```
145ffe3c632Sopenharmony_ci$ make php_c
146ffe3c632Sopenharmony_ci```
147ffe3c632Sopenharmony_ci
148ffe3c632Sopenharmony_ci### Node.js
149ffe3c632Sopenharmony_ci```
150ffe3c632Sopenharmony_ci$ make js
151ffe3c632Sopenharmony_ci```
152ffe3c632Sopenharmony_ci
153ffe3c632Sopenharmony_ciTo run a specific dataset or run with specific options:
154ffe3c632Sopenharmony_ci
155ffe3c632Sopenharmony_ci### Java:
156ffe3c632Sopenharmony_ci
157ffe3c632Sopenharmony_ci```
158ffe3c632Sopenharmony_ci$ make java-benchmark
159ffe3c632Sopenharmony_ci$ ./java-benchmark $(specific generated dataset file name) [$(caliper options)]
160ffe3c632Sopenharmony_ci```
161ffe3c632Sopenharmony_ci
162ffe3c632Sopenharmony_ci### CPP:
163ffe3c632Sopenharmony_ci
164ffe3c632Sopenharmony_ci```
165ffe3c632Sopenharmony_ci$ make cpp-benchmark
166ffe3c632Sopenharmony_ci$ ./cpp-benchmark $(specific generated dataset file name) [$(benchmark options)]
167ffe3c632Sopenharmony_ci```
168ffe3c632Sopenharmony_ci
169ffe3c632Sopenharmony_ci### Python:
170ffe3c632Sopenharmony_ci
171ffe3c632Sopenharmony_ciFor Python benchmark we have `--json` for outputting the json result
172ffe3c632Sopenharmony_ci
173ffe3c632Sopenharmony_ci#### Pure Python:
174ffe3c632Sopenharmony_ci
175ffe3c632Sopenharmony_ci```
176ffe3c632Sopenharmony_ci$ make python-pure-python-benchmark
177ffe3c632Sopenharmony_ci$ ./python-pure-python-benchmark [--json] $(specific generated dataset file name)
178ffe3c632Sopenharmony_ci```
179ffe3c632Sopenharmony_ci
180ffe3c632Sopenharmony_ci#### CPP reflection:
181ffe3c632Sopenharmony_ci
182ffe3c632Sopenharmony_ci```
183ffe3c632Sopenharmony_ci$ make python-cpp-reflection-benchmark
184ffe3c632Sopenharmony_ci$ ./python-cpp-reflection-benchmark [--json] $(specific generated dataset file name)
185ffe3c632Sopenharmony_ci```
186ffe3c632Sopenharmony_ci
187ffe3c632Sopenharmony_ci#### CPP generated code:
188ffe3c632Sopenharmony_ci
189ffe3c632Sopenharmony_ci```
190ffe3c632Sopenharmony_ci$ make python-cpp-generated-code-benchmark
191ffe3c632Sopenharmony_ci$ ./python-cpp-generated-code-benchmark [--json] $(specific generated dataset file name)
192ffe3c632Sopenharmony_ci```
193ffe3c632Sopenharmony_ci
194ffe3c632Sopenharmony_ci### Go:
195ffe3c632Sopenharmony_ci```
196ffe3c632Sopenharmony_ci$ make go-benchmark
197ffe3c632Sopenharmony_ci$ ./go-benchmark $(specific generated dataset file name) [go testing options]
198ffe3c632Sopenharmony_ci```
199ffe3c632Sopenharmony_ci
200ffe3c632Sopenharmony_ci### PHP
201ffe3c632Sopenharmony_ci#### Pure PHP
202ffe3c632Sopenharmony_ci```
203ffe3c632Sopenharmony_ci$ make php-benchmark
204ffe3c632Sopenharmony_ci$ ./php-benchmark $(specific generated dataset file name)
205ffe3c632Sopenharmony_ci```
206ffe3c632Sopenharmony_ci#### PHP with c extension
207ffe3c632Sopenharmony_ci```
208ffe3c632Sopenharmony_ci$ make php-c-benchmark
209ffe3c632Sopenharmony_ci$ ./php-c-benchmark $(specific generated dataset file name)
210ffe3c632Sopenharmony_ci```
211ffe3c632Sopenharmony_ci
212ffe3c632Sopenharmony_ci### Node.js
213ffe3c632Sopenharmony_ci```
214ffe3c632Sopenharmony_ci$ make js-benchmark
215ffe3c632Sopenharmony_ci$ ./js-benchmark $(specific generated dataset file name)
216ffe3c632Sopenharmony_ci```
217ffe3c632Sopenharmony_ci
218ffe3c632Sopenharmony_ci### C#
219ffe3c632Sopenharmony_ciFrom `csharp/src/Google.Protobuf.Benchmarks`, run:
220ffe3c632Sopenharmony_ci
221ffe3c632Sopenharmony_ci```
222ffe3c632Sopenharmony_ci$ dotnet run -c Release
223ffe3c632Sopenharmony_ci```
224ffe3c632Sopenharmony_ci
225ffe3c632Sopenharmony_ciWe intend to add support for this within the makefile in due course.
226ffe3c632Sopenharmony_ci
227ffe3c632Sopenharmony_ci## Benchmark datasets
228ffe3c632Sopenharmony_ci
229ffe3c632Sopenharmony_ciEach data set is in the format of benchmarks.proto:
230ffe3c632Sopenharmony_ci
231ffe3c632Sopenharmony_ci1. name is the benchmark dataset's name.
232ffe3c632Sopenharmony_ci2. message_name is the benchmark's message type full name (including package and message name)
233ffe3c632Sopenharmony_ci3. payload is the list of raw data.
234ffe3c632Sopenharmony_ci
235ffe3c632Sopenharmony_ciThe schema for the datasets is described in `benchmarks.proto`.
236ffe3c632Sopenharmony_ci
237ffe3c632Sopenharmony_ciBenchmark likely want to run several benchmarks against each data set (parse,
238ffe3c632Sopenharmony_ciserialize, possibly JSON, possibly using different APIs, etc).
239ffe3c632Sopenharmony_ci
240ffe3c632Sopenharmony_ciWe would like to add more data sets.  In general we will favor data sets
241ffe3c632Sopenharmony_cithat make the overall suite diverse without being too large or having
242ffe3c632Sopenharmony_citoo many similar tests.  Ideally everyone can run through the entire
243ffe3c632Sopenharmony_cisuite without the test run getting too long.
244