-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark
More file actions
executable file
·86 lines (70 loc) · 1.98 KB
/
benchmark
File metadata and controls
executable file
·86 lines (70 loc) · 1.98 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
#!/usr/bin/env bash
# --- Argument Parsing for Verbose Flag ---
verbose=false
while getopts "v" opt; do
case ${opt} in
v ) verbose=true
;;
\? ) echo "Usage: cmd [-v]"
exit 1
;;
esac
done
# --- Nix Environment Check ---
if [ -z "${IN_NIX_SHELL}" ]; then
echo "--> Not in Nix environment. Re-executing with 'nix develop'..."
exec nix develop --command "$0" "$@"
fi
set -e
cd "$(dirname "$0")"
# --- Helper function for building ---
run_build() {
local description=$1
shift
local command_str=$@
echo "$description"
if [ "$verbose" = true ]; then
(eval "$command_str")
else
(eval "$command_str") > /dev/null 2>&1
fi
}
# --- Build Step ---
echo "Building all implementations..."
run_build "Building Go..." "cd sieve_go && go build -ldflags='-s -w' -o sieve_go ."
run_build "Building C++..." "cd sieve_cpp && meson setup builddir --reconfigure && meson compile -C builddir"
run_build "Building Fortran..." "cd sieve_fortran && meson setup builddir --reconfigure && meson compile -C builddir"
run_build "Building Rust..." "cd sieve_rust && cargo build --release"
echo "All builds complete."
# --- Benchmark Step ---
P_VALUES="7 8 9"
RUNS=3
HYPERFINE_OPTS="--runs ${RUNS}"
print_header() {
echo ""
echo "--- $1 Benchmark ---"
}
# --- Go Benchmark ---
print_header "Go"
for p in ${P_VALUES}; do
echo "Benchmarking for N = 10^${p}"
hyperfine ${HYPERFINE_OPTS} "./sieve_go/sieve_go ${p}"
done
# --- C++ Benchmark ---
print_header "C++"
for p in ${P_VALUES}; do
echo "Benchmarking for N = 10^${p}"
hyperfine ${HYPERFINE_OPTS} "./sieve_cpp/builddir/sieve_cpp ${p}"
done
# --- Fortran Benchmark ---
print_header "Fortran"
for p in ${P_VALUES}; do
echo "Benchmarking for N = 10^${p}"
hyperfine ${HYPERFINE_OPTS} "./sieve_fortran/builddir/sieve_fortran ${p}"
done
# --- Rust Benchmark ---
print_header "Rust"
for p in ${P_VALUES}; do
echo "Benchmarking for N = 10^${p}"
hyperfine ${HYPERFINE_OPTS} "./sieve_rust/target/release/sieve_rust ${p}"
done