run.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. #
  3. # Change to repo root
  4. cd $(dirname $0)/../../..
  5. set -ex
  6. export OUTPUT_DIR=testoutput
  7. repo_root="$(pwd)"
  8. # TODO(jtattermusch): Add back support for benchmarking with tcmalloc for C++ and python.
  9. # This feature was removed since it used to use tcmalloc from https://github.com/gperftools/gperftools.git
  10. # which is very outdated. See https://github.com/protocolbuffers/protobuf/issues/8725.
  11. # download datasets for benchmark
  12. pushd benchmarks
  13. datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs)
  14. echo $datasets
  15. popd
  16. # build Python protobuf
  17. ./autogen.sh
  18. ./configure CXXFLAGS="-fPIC -O2"
  19. make -j8
  20. pushd python
  21. virtualenv -p python3 env
  22. source env/bin/activate
  23. python3 setup.py build --cpp_implementation
  24. pip3 install --install-option="--cpp_implementation" .
  25. popd
  26. # build and run Python benchmark
  27. # We do this before building protobuf C++ since C++ build
  28. # will rewrite some libraries used by protobuf python.
  29. pushd benchmarks
  30. make python-pure-python-benchmark
  31. make python-cpp-reflection-benchmark
  32. make -j8 python-cpp-generated-code-benchmark
  33. echo "[" > tmp/python_result.json
  34. echo "benchmarking pure python..."
  35. ./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json
  36. echo "," >> "tmp/python_result.json"
  37. echo "benchmarking python cpp reflection..."
  38. env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json
  39. echo "," >> "tmp/python_result.json"
  40. echo "benchmarking python cpp generated code..."
  41. 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
  42. echo "]" >> "tmp/python_result.json"
  43. popd
  44. # build CPP protobuf
  45. ./configure
  46. make clean && make -j8
  47. pushd java
  48. mvn package -B -Dmaven.test.skip=true
  49. popd
  50. pushd benchmarks
  51. # build and run C++ benchmark
  52. # "make clean" deletes the contents of the tmp/ directory, so we move it elsewhere and then restore it once build is done.
  53. # TODO(jtattermusch): find a less clumsy way of protecting python_result.json contents
  54. mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp
  55. echo "benchmarking cpp..."
  56. env ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets
  57. # TODO(jtattermusch): add benchmarks for https://github.com/protocolbuffers/protobuf-go.
  58. # The original benchmarks for https://github.com/golang/protobuf were removed
  59. # because:
  60. # * they were broken and haven't been producing results for a long time
  61. # * the https://github.com/golang/protobuf implementation has been superseded by
  62. # https://github.com/protocolbuffers/protobuf-go
  63. # build and run java benchmark (java 11 is required)
  64. make java-benchmark
  65. echo "benchmarking java..."
  66. ./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
  67. # TODO(jtattermusch): re-enable JS benchmarks once https://github.com/protocolbuffers/protobuf/issues/8747 is fixed.
  68. # build and run js benchmark
  69. # make js-benchmark
  70. # echo "benchmarking js..."
  71. # ./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json
  72. # TODO(jtattermusch): add php-c-benchmark. Currently its build is broken.
  73. # persist raw the results in the build job log (for better debuggability)
  74. cat tmp/cpp_result.json
  75. cat tmp/java_result.json
  76. cat tmp/python_result.json
  77. # print the postprocessed results to the build job log
  78. # TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken)
  79. make python_add_init
  80. env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \
  81. -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json"
  82. popd