Skip to content

Commit 1127dce

Browse files
committed
Add dev scripts [skip ci]
1 parent b3f70b9 commit 1127dce

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

benchmark_analysis.ipynb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "b49ae6d6",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas as pd\n",
11+
"import numpy as np\n",
12+
"import matplotlib.pyplot as plt\n",
13+
"import seaborn as sns\n",
14+
"\n",
15+
"plt.rcParams['figure.figsize'] = (16, 10)\n",
16+
"plt.rcParams['font.size'] = 11"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "d236980d",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"def parse_csv(filepath):\n",
27+
" with open(filepath, 'r') as f:\n",
28+
" lines = f.readlines()[1:]\n",
29+
" \n",
30+
" data = []\n",
31+
" for line in lines:\n",
32+
" line = line.strip()\n",
33+
" if line and ',' in line and not line.endswith(','):\n",
34+
" parts = line.split(',')\n",
35+
" if len(parts) >= 3:\n",
36+
" try:\n",
37+
" data.append({'Benchmark': parts[0].strip(), 'Time': float(parts[2])})\n",
38+
" except:\n",
39+
" continue\n",
40+
" return pd.DataFrame(data)\n",
41+
"\n",
42+
"baseline = parse_csv('BASELINE_bench.csv')\n",
43+
"custom = parse_csv('CUSTOM_AVX2_bench.csv')\n",
44+
"\n",
45+
"merged = baseline.merge(custom, on='Benchmark', suffixes=('_baseline', '_custom'))\n",
46+
"merged['improvement'] = ((merged['Time_baseline'] - merged['Time_custom']) / merged['Time_baseline']) * 100"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"id": "8442b12d",
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"sorted_data = merged.sort_values('improvement', ascending=False)\n",
57+
"top10 = sorted_data.head(10)\n",
58+
"bottom10 = sorted_data.tail(10)\n",
59+
"filtered = pd.concat([top10, bottom10])"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"id": "aa07550a",
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"heatmap_data = filtered.set_index('Benchmark')[['improvement']]\n",
70+
"\n",
71+
"plt.figure(figsize=(8, 12))\n",
72+
"sns.heatmap(heatmap_data, annot=True, fmt='.1f', cmap='RdYlGn', center=0, \n",
73+
" cbar_kws={'label': 'Performance Improvement (%)'})\n",
74+
"plt.title('CUSTOM_AVX2 vs BASELINE Performance (Top/Bottom 10)', fontsize=14, fontweight='bold')\n",
75+
"plt.ylabel('')\n",
76+
"plt.tight_layout()\n",
77+
"plt.show()"
78+
]
79+
}
80+
],
81+
"metadata": {
82+
"kernelspec": {
83+
"display_name": "Python 3",
84+
"language": "python",
85+
"name": "python3"
86+
},
87+
"language_info": {
88+
"codemirror_mode": {
89+
"name": "ipython",
90+
"version": 3
91+
},
92+
"file_extension": ".py",
93+
"mimetype": "text/x-python",
94+
"name": "python",
95+
"nbconvert_exporter": "python",
96+
"pygments_lexer": "ipython3",
97+
"version": "3.12.3"
98+
}
99+
},
100+
"nbformat": 4,
101+
"nbformat_minor": 5
102+
}

simd-bench.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
set -e
3+
4+
options=("OFF" "ON")
5+
BENCH_ITERS=${SECP256K1_BENCH_ITERS:-20000}
6+
7+
GREEN='\033[0;32m'
8+
RED='\033[0;31m'
9+
YELLOW='\033[1;33m'
10+
NC='\033[0m'
11+
12+
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo > /dev/null
13+
sudo cpupower -c 0 frequency-set -g performance > /dev/null
14+
command -v taskset > /dev/null && TASKSET_CMD="taskset -c 0"
15+
16+
run_bench() {
17+
local dir=$1 bin=$2 log=$3
18+
(
19+
cd "$dir"
20+
$TASKSET_CMD env SECP256K1_BENCH_ITERS=$BENCH_ITERS nice -n 0 ./bin/$bin >> "../../$log" 2>&1
21+
echo "" >> "../../$log"
22+
)
23+
}
24+
25+
bench_all() {
26+
local config="$1"
27+
local dir="build/$config"
28+
local log="${config}_bench.csv"
29+
30+
if [[ ! -d "$dir" ]]; then
31+
echo -e "${RED}$config${NC} (no dir)"
32+
return 1
33+
fi
34+
35+
{
36+
echo "Benchmark results for $config"
37+
echo "Generated on $(date)"
38+
echo "Iterations: $BENCH_ITERS"
39+
echo ""
40+
} > "$log"
41+
42+
for bin in bench bench_ecmult bench_internal; do
43+
if run_bench "$dir" "$bin" "$log"; then
44+
echo -e " ${GREEN}$bin${NC}"
45+
else
46+
echo -e " ${RED}$bin${NC}"
47+
return 1
48+
fi
49+
done
50+
51+
echo -e "${GREEN}$config${NC} (log: $log)"
52+
}
53+
54+
bench_all "BASELINE"
55+
bench_all "CUSTOM_AVX2"
56+
57+
echo -e "\n${YELLOW}All benchmarks successful. Logs in project root${NC}"

simd-build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
mkdir -p build
5+
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m'
10+
11+
run_build() {
12+
local config="$1"
13+
local flags="-O3 -mavx2 $2"
14+
local dir="build/$config"
15+
local log="${config}_build.log"
16+
17+
mkdir -p "$dir"
18+
19+
if (cd "$dir" && cmake ../.. -G Ninja -DCMAKE_BUILD_TYPE=Release -DSECP256K1_APPEND_CFLAGS="$flags" >"../../$log" 2>&1 && ninja >>"../../$log" 2>&1); then
20+
echo -e "${GREEN}$config${NC}"
21+
else
22+
echo -e "${RED}$config failed${NC}"
23+
return 1
24+
fi
25+
}
26+
27+
run_build "BASELINE" "-U__AVX2__"
28+
run_build "CUSTOM_AVX2" "-D__AVX2__"
29+
30+
echo -e "\n${YELLOW}All builds done. Logs in project root${NC}"

simd-test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
GREEN='\033[0;32m'
5+
RED='\033[0;31m'
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m'
8+
9+
run_test() {
10+
local config="$1"
11+
local dir="build/$config"
12+
local log="${config}_test.log"
13+
14+
if [[ ! -d "$dir" ]]; then
15+
echo -e "${RED}$config${NC} (no dir)"
16+
return 1
17+
fi
18+
19+
if (cd "$dir" && ctest --output-on-failure -j"$(nproc)" &> "../../$log"); then
20+
echo -e "${GREEN}$config${NC} (log: $log)"
21+
else
22+
echo -e "${RED}$config${NC} (log: $log)"
23+
return 1
24+
fi
25+
}
26+
27+
run_test "BASELINE"
28+
run_test "CUSTOM_AVX2"
29+
30+
echo -e "\n${YELLOW}All tests passed. Logs in project root${NC}"

0 commit comments

Comments
 (0)