-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (113 loc) · 3.95 KB
/
rust.yml
File metadata and controls
132 lines (113 loc) · 3.95 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Benchmark Rust version
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
env:
toolchain: nightly-2022-08-22
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
benchmark:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{env.toolchain}}
components: rustfmt, clippy
- name: Wait for PostgreSQL to be ready
run: |
echo "Waiting for PostgreSQL to be fully ready..."
for i in {1..30}; do
if pg_isready -h localhost -p 5432 -U postgres > /dev/null 2>&1; then
echo "PostgreSQL is ready!"
break
fi
echo "Attempt $i: PostgreSQL not ready yet..."
sleep 2
done
- name: Build benchmark
run: cargo build --release --all-features --manifest-path rust/Cargo.toml
- name: Run benchmark
working-directory: rust
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
# Use 100 links for main/master branch benchmarks, 10 for pull requests
BENCHMARK_LINKS: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) && '100' || '10' }}
# Use 1000 background links for main/master branch, 100 for pull requests
BENCHMARK_BACKGROUND_LINKS: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) && '1000' || '100' }}
run: |
set -o pipefail
cargo bench --bench bench -- --output-format bencher | tee out.txt
- name: Prepare benchmark results
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
run: |
git config --global user.email "linksplatform@gmail.com"
git config --global user.name "LinksPlatformBencher"
cd rust
pip install numpy matplotlib
python3 out.py
cd ..
# Create Docs directory if it doesn't exist
mkdir -p Docs
# Copy generated images
cp -f rust/bench_rust.png Docs/
cp -f rust/bench_rust_log_scale.png Docs/
# Update README with latest results
if [ -f rust/results.md ]; then
# Replace the results section in README.md
python3 -c "
import re
with open('rust/results.md', 'r') as f:
results = f.read()
with open('README.md', 'r') as f:
readme = f.read()
# Pattern to find and replace the results table
pattern = r'(\| Operation.*?\n\|[-|]+\n(?:\|.*?\n)*)'
if re.search(pattern, readme):
readme = re.sub(pattern, results.strip() + '\n', readme)
with open('README.md', 'w') as f:
f.write(readme)
"
fi
# Commit changes if any
git add Docs README.md
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update benchmark results"
git push origin HEAD
fi
- name: Save benchmark results
uses: actions/upload-artifact@v4
with:
name: Benchmark results
path: |
rust/bench_rust.png
rust/bench_rust_log_scale.png
rust/out.txt