-
Notifications
You must be signed in to change notification settings - Fork 12
/
rebuild_benchmark.sh
executable file
·111 lines (103 loc) · 3.41 KB
/
rebuild_benchmark.sh
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Copyright (c) 2023-2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -x
set -e
rm -rf src/bin
mkdir -p src/bin
cp tests/benchmark.rs src/bin/benchmark.rs
sed -E -i 's/\[dev-dependencies\]//g' Cargo.toml
micromap="micromap::Map"
capacities="2 4 8 16 32 64 128"
cycles=1000000
first=$(echo "${capacities}" | cut -f1 -d' ')
rm -rf target/benchmark
mkdir -p target/benchmark
SECONDS=0
for capacity in ${capacities}; do
sed -E -i "s/CAPACITY: usize = [0-9]+/CAPACITY: usize = ${capacity}/g" src/bin/benchmark.rs
cargo build --release
./target/release/benchmark "${cycles}" > "target/benchmark/${capacity}.out"
done
{
echo -n '| |'
for capacity in ${capacities}; do
echo -n " ${capacity} |"
done
echo ''
echo -n '| --- |'
for capacity in ${capacities}; do
echo -n " --: |"
done
echo ''
maps=$(cut -f 1 "target/benchmark/${first}.out")
for map in ${maps}; do
echo -n "| \`${map}\`"
if [ "${map}" == "${micromap}" ]; then
echo -n ' 👍'
fi
echo -n ' |'
for capacity in ${capacities}; do
our=$(grep "${micromap}" "target/benchmark/${capacity}.out" | cut -f 2)
if [ "${our}" -eq "0" ]; then
our=1
fi
their=$(grep "${map}" "target/benchmark/${capacity}.out" | cut -f 2)
if [ "${their}" -eq "0" ]; then
their=1
fi
echo -n ' '
if [ $(( "${their}" / "${our}" / 1000 / 1000 )) -gt 0 ]; then
perl -e "printf(\"%dM\", ${their} / ${our} / 1000 / 1000);"
elif [ $(( "${their}" / "${our}" / 1000 )) -gt 0 ]; then
perl -e "printf(\"%dK\", ${their} / ${our} / 1000);"
else
perl -e "printf(\"%.02f\", ${their} / ${our});"
fi
echo -n ' |'
done
echo ''
done
echo ''
echo "The experiment [was performed][action] on $(date +%d-%m-%Y)."
echo "There were ${cycles} repetition cycles."
echo "The entire benchmark took ${SECONDS}s."
echo "Uname: '$(uname)'."
} > target/benchmark/table.md
perl -e '
my $readme;
my $file = "README.md";
open(my $r, "<", $file);
{ local $/; $readme = <$r>; }
close($r);
my $sep = "<!-- benchmark -->";
my @p = split(/\Q$sep\E/, $readme);
my $table = "target/benchmark/table.md";
open(my $t, "<", $table);
{ local $/; $table = <$t>; }
close($t);
$p[1] = "\n" . $table . "\n";
my $new = join($sep, @p);
open(my $w, ">", $file);
print $w join($sep, @p);
close($w);
'
git restore Cargo.toml
rm -rf src/bin