-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·91 lines (75 loc) · 2.81 KB
/
Copy pathbenchmark.sh
File metadata and controls
executable file
·91 lines (75 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e
# Author: Renato Athaydes
#
# Add each program to be benchmarked to the COMMANDS array below!
# If compilation is required, also add instructions to do that before "Generating INPUTS"
#
JVM_OPTIONS="-Xms20M -Xmx100M"
COMMANDS=(
"java $JVM_OPTIONS -cp build/java Main" # Java
"java $JVM_OPTIONS -cp build/java Main2" # Java 2
"./lisp-phone-encoder" # Common Lisp
"./rust" # Rust
)
echo "Compiling Java sources"
rm -rf build || true
javac src/java/*.java -d build/java
javac src/java/util/*.java -d build/util
echo "Compiling Lisp sources"
cd src/lisp/
sbcl --non-interactive --load build.lisp
cp lisp-phone-encoder ../../
cd ../..
echo "Compiling Rust sources"
cd src/rust/phone_encoder && cargo build --release && cp target/release/phone_encoder ../../../rust
cd ../plotter && cargo build --release && cp target/release/plotter ../../../
cd ../benchmark_runner && cargo build --release && cp target/release/benchmark_runner ../../../
cd ../../..
echo "Generating inputs"
PRINT_INPUTS=(phones_1000.txt phones_100_000.txt phones_500_000.txt phones_1_000_000_with_empty.txt)
COUNT_INPUTS=(phones_1000.txt phones_2000.txt)
java -cp "build/util" util.GeneratePhoneNumbers 1000 > phones_1000.txt
java -cp "build/util" util.GeneratePhoneNumbers 2000 > phones_2000.txt
java -cp "build/util" util.GeneratePhoneNumbers 100000 > phones_100_000.txt
java -cp "build/util" util.GeneratePhoneNumbers 500000 > phones_500_000.txt
java -cp "build/util" util.GeneratePhoneNumbers 1000000 "true" > phones_1_000_000_with_empty.txt
CHECK_FILE="proc_out.txt"
DEFAULT_INPUT="input.txt"
DEFAULT_OUTPUT="output.txt"
DE_DICTIONARY="dictionary.txt"
EN_DICTIONARY="words-quarter.txt"
echo "Checking all programs for correctness"
for CMD in "${COMMANDS[@]}"
do
echo "Checking: $CMD"
$CMD print $DE_DICTIONARY $DEFAULT_INPUT > $CHECK_FILE
diff -q <(sort $CHECK_FILE) <(sort $DEFAULT_OUTPUT)
$CMD count $DE_DICTIONARY $DEFAULT_INPUT > $CHECK_FILE
if [ "$(cat $CHECK_FILE)" == "262" ]; then
echo "OK"
else
echo "count check failed, expected 262 but got '$(cat $CHECK_FILE)'"
exit 1
fi
done
CSV_OUT="benchmark-result.csv"
run_bench() {
DATA=$(./benchmark_runner $*)
echo "$DATA"
echo "$DATA" >> "$CSV_OUT"
}
echo "Benchmarking..."
echo "Proc,Run,Memory(bytes),Time(ms)"
echo "Proc,Run,Memory(bytes),Time(ms)" > "$CSV_OUT"
for CMD in "${COMMANDS[@]}"
do
echo "===> $CMD"
# shellcheck disable=SC2086
for file in "${PRINT_INPUTS[@]}"; do run_bench "$CMD print $DE_DICTIONARY $file"; done;
for file in "${COUNT_INPUTS[@]}"; do run_bench "$CMD count $EN_DICTIONARY $file"; done;
done
echo "Generating plot"
./plotter "$CSV_OUT"
echo "Cleaning up"
rm "${PRINT_INPUTS[@]} ${COUNT_INPUTS[@]} $CHECK_FILE ./rust ./benchmark_runner ./lisp-phone-encoder" > /dev/null 2>&1 || true