-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·47 lines (36 loc) · 845 Bytes
/
run.sh
File metadata and controls
executable file
·47 lines (36 loc) · 845 Bytes
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
#!/usr/bin/env bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 file"
exit 1
fi
SRC=$1
OPTIM="-O3"
for arg in "$@"; do
if [ "$arg" = "--debug" ]; then
OPTIM="-O0"
break
fi
done
now_ns() {
date +%s%N
}
ns_to_s() {
awk "BEGIN { printf \"%.6f\", $1 / 1e9 }"
}
compile_start=$(now_ns)
clang++ -std=c++23 -march=native "$OPTIM" "$SRC" -o run_binary
compile_status=$?
compile_end=$(now_ns)
if [ $compile_status -ne 0 ]; then
echo "Compilation failed"
exit 1
fi
compile_elapsed_ns=$((compile_end - compile_start))
echo "Compilation time: $(ns_to_s "$compile_elapsed_ns") s"
echo "Execution start: $(date -Iseconds)"
run_start=$(now_ns)
./run_binary
run_end=$(now_ns)
run_elapsed_ns=$((run_end - run_start))
echo "Compilation time: $(ns_to_s "$compile_elapsed_ns") s"
echo "Execution time: $(ns_to_s "$run_elapsed_ns") s"