build.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. #
  3. # Change to repo root
  4. cd $(dirname $0)/../../..
  5. export OUTPUT_DIR=testoutput
  6. oldpwd=`pwd`
  7. # tcmalloc
  8. if [ ! -f gperftools/.libs/libtcmalloc.so ]; then
  9. git clone https://github.com/gperftools/gperftools.git
  10. cd gperftools
  11. ./autogen.sh
  12. ./configure
  13. make -j8
  14. cd ..
  15. fi
  16. # download datasets for benchmark
  17. cd benchmarks
  18. ./download_data.sh
  19. datasets=`find . -type f -name "dataset.*.pb"`
  20. cd $oldpwd
  21. # build Python protobuf
  22. ./autogen.sh
  23. ./configure CXXFLAGS="-fPIC -O2"
  24. make -j8
  25. cd python
  26. python setup.py build --cpp_implementation
  27. pip install . --user
  28. # build and run Python benchmark
  29. cd ../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_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/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_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" LD_LIBRARY_PATH="$oldpwd/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. cd $oldpwd
  44. # build CPP protobuf
  45. ./configure
  46. make clean && make -j8
  47. # build Java protobuf
  48. cd java
  49. mvn package
  50. cd ..
  51. # build CPP benchmark
  52. cd benchmarks
  53. mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp
  54. echo "benchmarking cpp..."
  55. env LD_PRELOAD="$oldpwd/gperftools/.libs/libtcmalloc.so" ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets
  56. cd $oldpwd
  57. # build go protobuf
  58. export PATH="`pwd`/src:$PATH"
  59. export GOPATH="$HOME/gocode"
  60. mkdir -p "$GOPATH/src/github.com/google"
  61. rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
  62. ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
  63. export PATH="$GOPATH/bin:$PATH"
  64. go get github.com/golang/protobuf/protoc-gen-go
  65. # build go benchmark
  66. cd benchmarks
  67. make go-benchmark
  68. echo "benchmarking go..."
  69. ./go-benchmark $datasets > tmp/go_result.txt
  70. # build java benchmark
  71. make java-benchmark
  72. echo "benchmarking java..."
  73. ./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
  74. # upload result to bq
  75. make python_add_init
  76. env LD_LIBRARY_PATH="$oldpwd/src/.libs" python -m util.result_uploader -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" \
  77. -python="../tmp/python_result.json" -go="../tmp/go_result.txt"
  78. cd $oldpwd