-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRCPA-vs-PP-Comparison-Benchmark.yml
More file actions
115 lines (95 loc) · 4.14 KB
/
Copy pathRCPA-vs-PP-Comparison-Benchmark.yml
File metadata and controls
115 lines (95 loc) · 4.14 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
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
112
113
114
115
name: RCPA-vs-PP-Comparison-Benchmark
on:
workflow_dispatch:
permissions:
contents: write
jobs:
# --- Single Stage: Benchmark & Update ---
benchmark-and-update:
name: Sequential Benchmark (PP vs RCPA)
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Detect CPU
id: cpu_info
run: |
MODEL_NAME=$(grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | xargs)
if [[ "$MODEL_NAME" == *"AMD"* ]]; then VENDOR="AMD"; else VENDOR="INTEL"; fi
echo "vendor_tag=$VENDOR" >> $GITHUB_OUTPUT
echo "CPU_MODEL=$MODEL_NAME" >> $GITHUB_ENV
- name: Compile Sources
run: |
g++ -O3 -std=c++11 -march=native -ffast-math cpp/Ring_Cascade_Permutation_Algorithm.cpp -o rcpa_test -pthread
g++ -O3 -std=c++11 -march=native -ffast-math cpp/permpure_full.cpp -o pp_test -pthread
- name: Execute Sequential Benchmark
run: |
N_FACTORS=(10 11 12 13)
echo "Starting sequential benchmark..."
for n in "${N_FACTORS[@]}"; do
echo "Running N=$n..."
# PP Algorithm (Position Pure Algorithm)
P_OUT=$(./pp_test $n)
P_TIME=$(echo "$P_OUT" | grep "EXECUTION_TIME:" | awk '{print $2}')
# RCPA (Ring Cascade Permutation Algorithm)
R_OUT=$(./rcpa_test $n)
R_TIME=$(echo "$R_OUT" | grep "EXECUTION_TIME:" | awk '{print $2}')
# Calculate speedup (PP / RCPA) to show how much faster RCPA is
SPEEDUP=$(echo "scale=2; $P_TIME / $R_TIME" | bc)
echo "N=$n|P=$P_TIME|R=$R_TIME|S=$SPEEDUP" >> results_all.txt
done
- name: Sync to README
shell: python
run: |
import os, re
from datetime import datetime, timezone, timedelta
# 1. Environment Info
vendor = "${{ steps.cpu_info.outputs.vendor_tag }}"
cpu_str = "${{ env.CPU_MODEL }}"
# 2. Markers
start_tag = f"[//]: # (PP_VS_RCPA_{vendor}_START)"
end_tag = f"[//]: # (PP_VS_RCPA_{vendor}_END)"
# 3. Timestamp
now_utc = datetime.now(timezone.utc)
now_bj = now_utc + timedelta(hours=8)
ts_header = f"**Last Run:** {now_utc.strftime('%Y-%m-%d %H:%M:%S UTC')} / {now_bj.strftime('%Y-%m-%d %H:%M:%S (UTC+8)')}"
# 4. Table Header (Adjusted columns to put RCPA in the 2nd data column)
table = [
"### PP vs RCPA Performance Comparison",
ts_header,
f"**Processor:** `{cpu_str}`",
"",
"| N | PP Algorithm (s) | RCPA (s) | Speedup (RCPA vs PP) |",
"| :--- | :--- | :--- | :--- |"
]
# 5. Load results
data_points = []
if os.path.exists("results_all.txt"):
with open("results_all.txt", "r") as f:
for line in f:
# Pattern updated to: N|P|R|S
m = re.search(r"N=(\d+)\|P=([\d.]+)\|R=([\d.]+)\|S=([\d.]+)", line)
if m:
data_points.append(m.groups())
# 6. Sorting and Row Creation
for n, p, r, s in sorted(data_points, key=lambda x: int(x[0])):
table.append(f"| {n} | {p} s | {r} s | **{s}x** |")
final_content = "\n".join(table)
# 7. Update README.md
with open("README.md", "r", encoding="utf-8") as f:
readme = f.read()
pattern = re.escape(start_tag) + r".*?" + re.escape(end_tag)
if re.search(pattern, readme, re.DOTALL):
updated_readme = re.sub(pattern, f"{start_tag}\n\n{final_content}\n\n{end_tag}", readme, flags=re.DOTALL)
with open("README.md", "w", encoding="utf-8") as f:
f.write(updated_readme)
else:
print(f"Error: Markers not found.")
exit(1)
- name: Commit and Push
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "docs: adjust PP vs RCPA table layout [skip ci]" || exit 0
git push origin main