Python Iter Performance Bench #61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |