Skip to content

Commit 22fd855

Browse files
authored
Benchmark crate for core features (yewstack#3487)
* Benchmark crate for core features * Fix incorrectly interpreted backticks * Add VSuspense node in benchmark
1 parent 1b9d294 commit 22fd855

File tree

5 files changed

+324
-3
lines changed

5 files changed

+324
-3
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
name: Benchmark - core
3+
4+
on:
5+
pull_request:
6+
branches: [master]
7+
paths:
8+
- .github/workflows/benchmark-core.yml
9+
- "packages/yew/**"
10+
- "tools/benchmark-core/**"
11+
12+
jobs:
13+
benchmark-core:
14+
name: Benchmark - core
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout master
19+
uses: actions/checkout@v3
20+
with:
21+
repository: "yewstack/yew"
22+
ref: master
23+
path: yew-master
24+
25+
- name: Checkout pull request
26+
uses: actions/checkout@v3
27+
with:
28+
path: current-pr
29+
30+
- name: Setup toolchain
31+
uses: dtolnay/rust-toolchain@master
32+
with:
33+
toolchain: stable
34+
35+
- name: Restore Rust cache for master
36+
uses: Swatinem/rust-cache@v2
37+
with:
38+
working-directory: yew-master
39+
key: master
40+
41+
- name: Restore Rust cache for current pull request
42+
uses: Swatinem/rust-cache@v2
43+
with:
44+
working-directory: current-pr
45+
key: pr
46+
47+
- name: Run pull request benchmark
48+
run: cargo bench -q > ../output.log
49+
working-directory: current-pr/tools/benchmark-core
50+
51+
- name: Run master benchmark
52+
run: cargo bench -q > ../output.log
53+
continue-on-error: true
54+
working-directory: yew-master/tools/benchmark-core
55+
56+
- name: Make sure master's output log exists
57+
run: touch yew-master/tools/output.log
58+
59+
- name: Write Pull Request ID
60+
run: |
61+
echo "${{ github.event.number }}" > .PR_NUMBER
62+
63+
- name: Upload Artifact
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: benchmark-core
67+
path: |
68+
.PR_NUMBER
69+
yew-master/tools/output.log
70+
current-pr/tools/output.log
71+
retention-days: 1
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
name: Post Comment for Benchmark - core
3+
4+
on:
5+
workflow_run:
6+
workflows: ["Benchmark - core"]
7+
types:
8+
- completed
9+
10+
jobs:
11+
post-benchmark-core:
12+
if: github.event.workflow_run.event == 'pull_request'
13+
name: Post Comment on Pull Request
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Download Repository
18+
uses: actions/checkout@v3
19+
20+
- name: Download Artifact
21+
uses: Legit-Labs/action-download-artifact@v2
22+
with:
23+
github_token: "${{ secrets.GITHUB_TOKEN }}"
24+
workflow: benchmark-core.yml
25+
run_id: ${{ github.event.workflow_run.id }}
26+
name: benchmark-core
27+
path: "benchmark-core/"
28+
29+
- name: Make pull request comment
30+
run: |
31+
cat - >>comment.txt <<EOF
32+
### Benchmark - core
33+
#### Yew Master
34+
\`\`\`
35+
EOF
36+
cat benchmark-core/yew-master/tools/output.json >>comment.txt
37+
cat - >>comment.txt <<EOF
38+
\`\`\`
39+
#### Pull Request" >> comment.txt
40+
\`\`\`
41+
EOF
42+
cat benchmark-core/current-pr/tools/output.json >>comment.txt
43+
cat - >>comment.txt <<EOF
44+
\`\`\`
45+
EOF
46+
47+
- name: Read Pull Request ID
48+
run: |
49+
PR_NUMBER=$(cat "benchmark-core/.PR_NUMBER")
50+
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
51+
echo "pr number invalid"
52+
exit 1
53+
fi
54+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
55+
56+
- name: Post Comment
57+
uses: actions/github-script@v6
58+
with:
59+
script: |
60+
const fs = require('fs');
61+
62+
const commentInfo = {
63+
...context.repo,
64+
issue_number: ${{ env.PR_NUMBER }},
65+
};
66+
67+
const comment = {
68+
...commentInfo,
69+
body: fs.readFileSync("comment.txt", 'utf-8'),
70+
};
71+
72+
function isCommentByBot(comment) {
73+
return comment.user.type === "Bot" && comment.body.includes("### Benchmark - core");
74+
}
75+
76+
let commentId = null;
77+
const comments = (await github.rest.issues.listComments(commentInfo)).data;
78+
for (let i = comments.length; i--; ) {
79+
const c = comments[i];
80+
if (isCommentByBot(c)) {
81+
commentId = c.id;
82+
break;
83+
}
84+
}
85+
86+
if (commentId) {
87+
try {
88+
await github.rest.issues.updateComment({
89+
...context.repo,
90+
comment_id: commentId,
91+
body: comment.body,
92+
});
93+
} catch (e) {
94+
commentId = null;
95+
}
96+
}
97+
98+
if (!commentId) {
99+
await github.rest.issues.createComment(comment);
100+
}

Cargo.lock

Lines changed: 109 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/benchmark-core/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "benchmark-core"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[[bench]]
9+
name = "vnode"
10+
harness = false
11+
12+
[dependencies]
13+
divan = "0.1.0"
14+
yew = { path = "../../packages/yew" }

0 commit comments

Comments
 (0)