blob: 963f7796ab4b34fe3f2b5fc5f8bcd59bf71823bf [file] [log] [blame]
Yilun Chong6adc3d72018-12-18 16:20:23 -08001#!/bin/bash
2#
3# Change to repo root
4cd $(dirname $0)/../../..
5
Jan Tattermusch6135c912021-05-27 10:30:12 +02006set -ex
7
Yilun Chong6adc3d72018-12-18 16:20:23 -08008export OUTPUT_DIR=testoutput
Jan Tattermusch6135c912021-05-27 10:30:12 +02009repo_root="$(pwd)"
Yilun Chong6adc3d72018-12-18 16:20:23 -080010
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020011# TODO(jtattermusch): Add back support for benchmarking with tcmalloc for C++ and python.
12# This feature was removed since it used to use tcmalloc from https://github.com/gperftools/gperftools.git
13# which is very outdated. See https://github.com/protocolbuffers/protobuf/issues/8725.
Yilun Chong6adc3d72018-12-18 16:20:23 -080014
15# download datasets for benchmark
Jan Tattermusch6135c912021-05-27 10:30:12 +020016pushd benchmarks
Yilun Chong6adc3d72018-12-18 16:20:23 -080017datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs)
18echo $datasets
Jan Tattermusch6135c912021-05-27 10:30:12 +020019popd
Yilun Chong6adc3d72018-12-18 16:20:23 -080020
21# build Python protobuf
22./autogen.sh
23./configure CXXFLAGS="-fPIC -O2"
24make -j8
Jan Tattermusch6135c912021-05-27 10:30:12 +020025pushd python
Adam Cozzette250fafa2022-02-11 16:25:56 -080026python3 -m venv env
Adam Cozzette6a9cf182021-11-01 09:00:31 -070027source env/bin/activate
28python3 setup.py build --cpp_implementation
29pip3 install --install-option="--cpp_implementation" .
Jan Tattermusch6135c912021-05-27 10:30:12 +020030popd
Yilun Chong6adc3d72018-12-18 16:20:23 -080031
32# build and run Python benchmark
Jan Tattermusch6135c912021-05-27 10:30:12 +020033# We do this before building protobuf C++ since C++ build
34# will rewrite some libraries used by protobuf python.
35pushd benchmarks
Yilun Chong6adc3d72018-12-18 16:20:23 -080036make python-pure-python-benchmark
37make python-cpp-reflection-benchmark
38make -j8 python-cpp-generated-code-benchmark
39echo "[" > tmp/python_result.json
40echo "benchmarking pure python..."
41./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json
42echo "," >> "tmp/python_result.json"
43echo "benchmarking python cpp reflection..."
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020044env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json
Yilun Chong6adc3d72018-12-18 16:20:23 -080045echo "," >> "tmp/python_result.json"
46echo "benchmarking python cpp generated code..."
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020047env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-generated-code-benchmark --json --behavior_prefix="cpp-generated-code-benchmark" $datasets >> tmp/python_result.json
Yilun Chong6adc3d72018-12-18 16:20:23 -080048echo "]" >> "tmp/python_result.json"
Jan Tattermusch6135c912021-05-27 10:30:12 +020049popd
Yilun Chong6adc3d72018-12-18 16:20:23 -080050
51# build CPP protobuf
52./configure
53make clean && make -j8
54
Jan Tattermusch6135c912021-05-27 10:30:12 +020055pushd java
Jan Tattermuschceafbf92021-05-27 12:29:29 +020056mvn package -B -Dmaven.test.skip=true
Jan Tattermusch6135c912021-05-27 10:30:12 +020057popd
Yilun Chong6adc3d72018-12-18 16:20:23 -080058
Jan Tattermusch6135c912021-05-27 10:30:12 +020059pushd benchmarks
60
61# build and run C++ benchmark
Jan Tattermuschceafbf92021-05-27 12:29:29 +020062# "make clean" deletes the contents of the tmp/ directory, so we move it elsewhere and then restore it once build is done.
63# TODO(jtattermusch): find a less clumsy way of protecting python_result.json contents
Yilun Chong6adc3d72018-12-18 16:20:23 -080064mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp
65echo "benchmarking cpp..."
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020066env ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets
Yilun Chong6adc3d72018-12-18 16:20:23 -080067
Jan Tattermusch6135c912021-05-27 10:30:12 +020068# TODO(jtattermusch): add benchmarks for https://github.com/protocolbuffers/protobuf-go.
69# The original benchmarks for https://github.com/golang/protobuf were removed
70# because:
71# * they were broken and haven't been producing results for a long time
72# * the https://github.com/golang/protobuf implementation has been superseded by
73# https://github.com/protocolbuffers/protobuf-go
Yilun Chong6adc3d72018-12-18 16:20:23 -080074
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020075# build and run java benchmark (java 11 is required)
Yilun Chong6adc3d72018-12-18 16:20:23 -080076make java-benchmark
77echo "benchmarking java..."
78./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
79
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020080# TODO(jtattermusch): re-enable JS benchmarks once https://github.com/protocolbuffers/protobuf/issues/8747 is fixed.
Jan Tattermusch6135c912021-05-27 10:30:12 +020081# build and run js benchmark
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020082# make js-benchmark
83# echo "benchmarking js..."
84# ./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json
Yilun Chong6adc3d72018-12-18 16:20:23 -080085
Jan Tattermusch75afc882021-05-27 11:32:50 +020086# TODO(jtattermusch): add php-c-benchmark. Currently its build is broken.
Yilun Chong6adc3d72018-12-18 16:20:23 -080087
Jan Tattermuschb4a06a12021-05-27 13:54:26 +020088# persist raw the results in the build job log (for better debuggability)
89cat tmp/cpp_result.json
90cat tmp/java_result.json
91cat tmp/python_result.json
Jan Tattermuschb4a06a12021-05-27 13:54:26 +020092
93# print the postprocessed results to the build job log
94# TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken)
Yilun Chong6adc3d72018-12-18 16:20:23 -080095make python_add_init
Adam Cozzette6a9cf182021-11-01 09:00:31 -070096env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \
Jan Tattermuscha8b73fb2021-09-03 18:24:32 +020097 -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json"
Jan Tattermusch6135c912021-05-27 10:30:12 +020098popd
Jan Tattermuschceafbf92021-05-27 12:29:29 +020099