Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Change to repo root |
| 4 | cd $(dirname $0)/../../.. |
| 5 | |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 6 | set -ex |
| 7 | |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 8 | export OUTPUT_DIR=testoutput |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 9 | repo_root="$(pwd)" |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 10 | |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 11 | # 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 Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 14 | |
| 15 | # download datasets for benchmark |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 16 | pushd benchmarks |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 17 | datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs) |
| 18 | echo $datasets |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 19 | popd |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 20 | |
| 21 | # build Python protobuf |
| 22 | ./autogen.sh |
| 23 | ./configure CXXFLAGS="-fPIC -O2" |
| 24 | make -j8 |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 25 | pushd python |
Adam Cozzette | 250fafa | 2022-02-11 16:25:56 -0800 | [diff] [blame^] | 26 | python3 -m venv env |
Adam Cozzette | 6a9cf18 | 2021-11-01 09:00:31 -0700 | [diff] [blame] | 27 | source env/bin/activate |
| 28 | python3 setup.py build --cpp_implementation |
| 29 | pip3 install --install-option="--cpp_implementation" . |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 30 | popd |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 31 | |
| 32 | # build and run Python benchmark |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 33 | # We do this before building protobuf C++ since C++ build |
| 34 | # will rewrite some libraries used by protobuf python. |
| 35 | pushd benchmarks |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 36 | make python-pure-python-benchmark |
| 37 | make python-cpp-reflection-benchmark |
| 38 | make -j8 python-cpp-generated-code-benchmark |
| 39 | echo "[" > tmp/python_result.json |
| 40 | echo "benchmarking pure python..." |
| 41 | ./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json |
| 42 | echo "," >> "tmp/python_result.json" |
| 43 | echo "benchmarking python cpp reflection..." |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 44 | env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 45 | echo "," >> "tmp/python_result.json" |
| 46 | echo "benchmarking python cpp generated code..." |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 47 | env 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 Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 48 | echo "]" >> "tmp/python_result.json" |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 49 | popd |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 50 | |
| 51 | # build CPP protobuf |
| 52 | ./configure |
| 53 | make clean && make -j8 |
| 54 | |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 55 | pushd java |
Jan Tattermusch | ceafbf9 | 2021-05-27 12:29:29 +0200 | [diff] [blame] | 56 | mvn package -B -Dmaven.test.skip=true |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 57 | popd |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 58 | |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 59 | pushd benchmarks |
| 60 | |
| 61 | # build and run C++ benchmark |
Jan Tattermusch | ceafbf9 | 2021-05-27 12:29:29 +0200 | [diff] [blame] | 62 | # "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 Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 64 | mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp |
| 65 | echo "benchmarking cpp..." |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 66 | env ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 67 | |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 68 | # 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 Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 74 | |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 75 | # build and run java benchmark (java 11 is required) |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 76 | make java-benchmark |
| 77 | echo "benchmarking java..." |
| 78 | ./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets |
| 79 | |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 80 | # TODO(jtattermusch): re-enable JS benchmarks once https://github.com/protocolbuffers/protobuf/issues/8747 is fixed. |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 81 | # build and run js benchmark |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 82 | # make js-benchmark |
| 83 | # echo "benchmarking js..." |
| 84 | # ./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 85 | |
Jan Tattermusch | 75afc88 | 2021-05-27 11:32:50 +0200 | [diff] [blame] | 86 | # TODO(jtattermusch): add php-c-benchmark. Currently its build is broken. |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 87 | |
Jan Tattermusch | b4a06a1 | 2021-05-27 13:54:26 +0200 | [diff] [blame] | 88 | # persist raw the results in the build job log (for better debuggability) |
| 89 | cat tmp/cpp_result.json |
| 90 | cat tmp/java_result.json |
| 91 | cat tmp/python_result.json |
Jan Tattermusch | b4a06a1 | 2021-05-27 13:54:26 +0200 | [diff] [blame] | 92 | |
| 93 | # print the postprocessed results to the build job log |
| 94 | # TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken) |
Yilun Chong | 6adc3d7 | 2018-12-18 16:20:23 -0800 | [diff] [blame] | 95 | make python_add_init |
Adam Cozzette | 6a9cf18 | 2021-11-01 09:00:31 -0700 | [diff] [blame] | 96 | env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \ |
Jan Tattermusch | a8b73fb | 2021-09-03 18:24:32 +0200 | [diff] [blame] | 97 | -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json" |
Jan Tattermusch | 6135c91 | 2021-05-27 10:30:12 +0200 | [diff] [blame] | 98 | popd |
Jan Tattermusch | ceafbf9 | 2021-05-27 12:29:29 +0200 | [diff] [blame] | 99 | |