• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3set -e
4set -o pipefail
5
6prefix_with() (
7  local PREFIX=("$@")
8  while read line
9  do
10    echo "${PREFIX[@]}" "$line"
11  done
12)
13
14progress() (
15  local EXPECTED_LINES=$1
16  local I=0
17  echo "0/$EXPECTED_LINES (0%)" >&2
18  while read line
19  do
20    echo "$line"
21    I="$[$I + 1]"
22    echo "$I/$EXPECTED_LINES ($[100 * $I / $EXPECTED_LINES]%)" >&2
23  done
24)
25
26print_stats() (
27  local TOTAL=0
28  local N=0
29  for VALUE in "$@"
30  do
31    TOTAL="$(echo $TOTAL + $VALUE | bc -l)"
32    N="$[$N + 1]"
33  done
34  if [[ $N == 0 ]]
35  then
36    echo "N/A ()"
37  else
38    echo "$(echo $TOTAL / $N | bc -l) ($@)"
39  fi
40)
41
42BASEDIR="$PWD"
43COMPILERS=(g++ clang++)
44# NUM_ITERATIONS = ITERATIONS_FACTOR/NUM_BINDINGS
45ITERATIONS_FACTOR="$[400 * 1000 * 1000]"
46# Must be multiples of 10
47NUM_BINDINGS_FOR_RUNTIME_TESTS=(100 1000)
48# Must be multiples of 5
49NUM_BINDINGS_FOR_COMPILE_TESTS=(20 80 320)
50NUM_LINES="$[${#COMPILERS[@]} * (${#NUM_BINDINGS_FOR_RUNTIME_TESTS[@]} * 3 + ${#NUM_BINDINGS_FOR_COMPILE_TESTS[@]})]"
51
52# All result lines are of the form:
53# <compiler> <n> <test> <avg. time> (<time>...)
54for compiler in ${COMPILERS[@]}
55do
56  rm -rf build
57  mkdir build
58  (
59    cd build
60    cmake .. -DCMAKE_CXX_COMPILER=$(which $compiler) -DCMAKE_BUILD_TYPE=Release &>/dev/null
61    (
62      cd examples/benchmark
63      for N in ${NUM_BINDINGS_FOR_RUNTIME_TESTS[@]}
64      do
65        (
66          NUM_ITERATIONS="$[$ITERATIONS_FACTOR / $N]"
67          sed -i "s/num_components_with_no_deps = .*/num_components_with_no_deps = $[$N / 10];/" $BASEDIR/examples/benchmark/generate_benchmark.cpp
68          sed -i "s/num_components_with_deps    = .*/num_components_with_deps    = $[9 * ($N / 10)];/" $BASEDIR/examples/benchmark/generate_benchmark.cpp
69          make benchmark &>/dev/null
70          SETUP_TIMES=()
71          REQUEST_TIMES=()
72          for i in $(seq 1 4)
73          do
74            RESULTS=($(echo $NUM_ITERATIONS | ./main $NUM_ITERATIONS | fgrep Total | awk '{print $5}'))
75            SETUP_TIMES+=("${RESULTS[0]}")
76            REQUEST_TIMES+=("${RESULTS[1]}")
77          done
78          print_stats "${SETUP_TIMES[@]}" | prefix_with "fruit_setup_time"
79          print_stats "${REQUEST_TIMES[@]}" | prefix_with "fruit_request_time"
80          sed -i "s/#define MULTIPLIER .*/#define MULTIPLIER $N/" $BASEDIR/examples/benchmark/new_delete_benchmark.cpp
81          make new_delete_benchmark &>/dev/null
82          NEW_DELETE_TIMES=()
83          for i in $(seq 1 4)
84          do
85            NEW_DELETE_TIMES+=($(echo $NUM_ITERATIONS | ./new_delete_benchmark | awk '{print $3}'))
86          done
87          print_stats "${NEW_DELETE_TIMES[@]}" | prefix_with "new_delete_time"
88        ) | prefix_with $N
89      done
90    )
91    (
92      cd examples/compile_time_benchmark
93      for N in ${NUM_BINDINGS_FOR_COMPILE_TESTS[@]}
94      do
95        (
96          sed -i "s/#define MULTIPLIER .*/#define MULTIPLIER $[$N/5]/" $BASEDIR/examples/compile_time_benchmark/module.cpp
97          COMPILE_TIMES=()
98          for i in $(seq 1 4)
99          do
100            COMPILE_TIMES+=($(make compile_time_benchmark 2>&1 | fgrep real | awk '{print $2}' | tr -d s | sed 's/m/*60+/' | bc))
101          done
102          print_stats "${COMPILE_TIMES[@]}" | prefix_with "fruit_compile_time"
103        ) | prefix_with "$[$N * 5]"
104      done
105    )
106  ) | prefix_with $compiler
107done | progress $NUM_LINES
108