1#!/bin/bash
2#
3# Change to repo root
4cd $(dirname $0)/../../..
5
6export OUTPUT_DIR=testoutput
7oldpwd=`pwd`
8
9# tcmalloc
10if [ ! -f gperftools/.libs/libtcmalloc.so ]; then
11  git clone https://github.com/gperftools/gperftools.git
12  cd gperftools
13  ./autogen.sh
14  ./configure
15  make -j8
16  cd ..
17fi
18
19# download datasets for benchmark
20cd benchmarks
21./download_data.sh
22datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs)
23echo $datasets
24cd $oldpwd
25
26# build Python protobuf
27./autogen.sh
28./configure CXXFLAGS="-fPIC -O2"
29make -j8
30cd python
31python setup.py build --cpp_implementation
32pip install . --user
33
34
35# build and run Python benchmark
36cd ../benchmarks
37make python-pure-python-benchmark
38make python-cpp-reflection-benchmark
39make -j8 python-cpp-generated-code-benchmark
40echo "[" > tmp/python_result.json
41echo "benchmarking pure python..."
42./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets  >> tmp/python_result.json
43echo "," >> "tmp/python_result.json"
44echo "benchmarking python cpp reflection..."
45env 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
46echo "," >> "tmp/python_result.json"
47echo "benchmarking python cpp generated code..."
48env 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
49echo "]" >> "tmp/python_result.json"
50cd $oldpwd
51
52# build CPP protobuf
53./configure
54make clean && make -j8
55
56# build Java protobuf
57cd java
58mvn package
59cd ..
60
61# build CPP benchmark
62cd benchmarks
63mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp
64echo "benchmarking cpp..."
65env 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
66cd $oldpwd
67
68# build go protobuf
69export PATH="`pwd`/src:$PATH"
70export GOPATH="$HOME/gocode"
71mkdir -p "$GOPATH/src/github.com/google"
72rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
73ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
74export PATH="$GOPATH/bin:$PATH"
75go get github.com/golang/protobuf/protoc-gen-go
76
77# build go benchmark
78cd benchmarks
79make go-benchmark
80echo "benchmarking go..."
81./go-benchmark $datasets > tmp/go_result.txt
82
83# build java benchmark
84make java-benchmark
85echo "benchmarking java..."
86./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
87
88make js-benchmark
89echo "benchmarking js..."
90./js-benchmark $datasets  --json_output=$(pwd)/tmp/node_result.json
91
92make -j8 generate_proto3_data
93proto3_datasets=$(for file in $datasets; do echo $(pwd)/tmp/proto3_data/${file#$(pwd)}; done | xargs)
94echo $proto3_datasets
95
96# build php benchmark
97make -j8 php-c-benchmark
98echo "benchmarking php_c..."
99./php-c-benchmark $proto3_datasets --json --behavior_prefix="php_c" > tmp/php_c_result.json
100
101# upload result to bq
102make python_add_init
103env LD_LIBRARY_PATH="$oldpwd/src/.libs" python -m util.result_uploader -php_c="../tmp/php_c_result.json"  \
104	-cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -go="../tmp/go_result.txt" -python="../tmp/python_result.json" -node="../tmp/node_result.json"
105cd $oldpwd
106