-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (68 loc) · 2.8 KB
/
python_iter_bench.yml
File metadata and controls
84 lines (68 loc) · 2.8 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
name: Python Iter Performance Bench
on:
# push:
# branches: [ "main" ]
workflow_dispatch:
concurrency:
group: global-readme-sync
cancel-in-progress: false
permissions:
contents: write
jobs:
python-bench:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up PyPy 3.10
uses: actions/setup-python@v5
with:
python-version: 'pypy-3.10'
- name: Run Benchmark
run: |
cd python
python pp_iter.py > raw_bench.log
- name: Update README with CPU Detection
shell: python
run: |
import os, datetime, subprocess, sys
# Detect CPU Vendor
cpu_info = subprocess.check_output("grep -m 1 'model name' /proc/cpuinfo", shell=True).decode()
cpu_model = cpu_info.split(":")[1].strip()
vendor = "AMD" if "AMD" in cpu_model.upper() else "INTEL"
# Match Markers
start_m = f"[//]: # (PYTHON_PP_ITER_BENCHMARK_{vendor}_START)"
end_m = f"[//]: # (PYTHON_PP_ITER_BENCHMARK_{vendor}_END)"
# Unified Timestamp
now_utc = datetime.datetime.now(datetime.timezone.utc)
now_bj = now_utc + datetime.timedelta(hours=8)
time_str = f"{now_utc.strftime('%a %b %d %H:%M:%S %Y')} UTC / {now_bj.strftime('%a %b %d %H:%M:%S %Y')} (UTC+8)"
with open("python/raw_bench.log", "r") as f:
clean_data = "\n".join([l.strip() for l in f.readlines() if l.strip()])
header = f"**Last Run:** {time_str}\n**Environment:** {cpu_model} (GitHub Actions Runner)"
with open("README.md", "r", encoding="utf-8") as f:
readme = f.read()
if start_m in readme and end_m in readme:
prefix, suffix = readme.split(start_m)[0], readme.split(end_m)[1]
updated = f"{prefix}{start_m}\n\n{header}\n\n{clean_data}\n\n{end_m}{suffix}"
with open("README.md", "w", encoding="utf-8") as f:
f.write(updated)
else:
print(f"Error: Markers for {vendor} not found!")
sys.exit(1)
- name: Synchronized Git Push
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
for i in {1..5}; do
git add README.md
if git commit -m "docs: sync python benchmarks [skip ci]"; then
git pull --rebase origin main
if git push; then exit 0; fi
else
exit 0
fi
sleep 5
done