-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.sh
executable file
·55 lines (44 loc) · 1.82 KB
/
profile.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
#!/bin/bash
packages=("poseidon" "rlp" "keccak" "keccak_2x")
TIME_FORMAT='
Elapsed Time: %E
User Time: %U
System Time: %S
CPU Usage: %P
Max Memory: %M'
convert_memory() {
local kilobytes=$1
local megabytes=$(echo "scale=2; $kilobytes / 1024" | bc)
if (( $(echo "$megabytes < 1024" | bc -l) )); then
echo "${megabytes}MB"
else
local gigabytes=$(echo "scale=2; $megabytes / 1024" | bc)
echo "${gigabytes}GB"
fi
}
profile_command() {
local package=$1
local tool=$2
local action=$3
local command=$4
temp_file=$(mktemp)
gtime -f "$TIME_FORMAT" bash -c "$command" > "$temp_file" 2>&1
output=$(<"$temp_file")
elapsed_time=$(echo "$output" | grep 'Elapsed Time' | awk '{print $3}')
user_time=$(echo "$output" | grep 'User Time' | awk '{print $3 " " $4}')
system_time=$(echo "$output" | grep 'System Time' | awk '{print $3 " " $4}')
cpu_usage=$(echo "$output" | grep 'CPU Usage' | awk '{print $3}')
max_memory_kb=$(echo "$output" | grep 'Max Memory' | awk '{print $3}')
max_memory=$(convert_memory "$max_memory_kb")
echo "| $package | $tool | $action | $elapsed_time | $user_time | $system_time | $cpu_usage | $max_memory |"
rm "$temp_file"
}
yarn build
echo "| Package | Tool | Action | Elapsed Time | User Time | System Time | CPU Usage | Max Memory |"
echo "|---------|------|--------|--------------|-----------|-------------|-----------|------------|"
for package in "${packages[@]}"; do
profile_command "$package" "nargo" "prove" "nargo prove --package=${package}"
profile_command "$package" "nargo" "verify" "nargo verify --package=${package}"
profile_command "$package" "noir_js" "prove" "yarn start --package=${package} --action=prove"
profile_command "$package" "noir_js" "verify" "yarn start --package=${package} --action=verify"
done