Skip to content

Commit

Permalink
feat: benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Qun committed Jul 13, 2024
1 parent 904cb39 commit b00afe2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 37 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Benchmarks

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]

permissions:
issues: write

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.2.0
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: pnpm run benchmarks
- run: |
FILES=("benchmarks/simple-read.json" "benchmarks/simple-write.json" "benchmarks/subscribe-write.json")
echo "## Benchmark Results" > table.md
for file in "${FILES[@]}"; do
if [ -f "$file" ]; then
name=$(jq -r '.name' "$file")
echo "### $name" >> table.md
echo "| Test Case | Ops/sec | Margin of Error |" >> table.md
echo "|-----------|---------|-----------------|" >> table.md
jq -r '.results[] | "| \(.name) | \(.ops) | \(.margin)% |"' "$file" >> table.md
echo "" >> table.md
fi
done
cat table.md
- run: |
table_content=$(cat table.md)
echo "table_content<<EOF" >> $GITHUB_ENV
echo "$table_content" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ env.table_content }}
2 changes: 0 additions & 2 deletions benchmarks/simple-read.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env npx tsx

import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import type { PrimitiveAtom } from '../src/vanilla/atom.ts'
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/simple-write.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env npx tsx

import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import type { PrimitiveAtom } from '../src/vanilla/atom.ts'
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/subscribe-write.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env npx tsx

import { add, complete, cycle, save, suite } from 'benny'
import { atom } from '../src/vanilla/atom.ts'
import type { PrimitiveAtom } from '../src/vanilla/atom.ts'
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
"patch-ts3.8": "node -e \"require('shelljs').find('dist/ts3.8/**/*.d.ts').forEach(f=>require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;'))\"",
"patch-old-ts": "shx touch dist/ts_version_3.8_and_above_is_required.d.ts",
"patch-esm-ts": "node -e \"require('shelljs').find('dist/esm/**/*.d.ts').forEach(f=>{var f2=f.replace(/\\.ts$/,'.mts');require('fs').renameSync(f,f2);require('shelljs').sed('-i',/ from '(\\.[^']+)';$/,' from \\'\\$1.mjs\\';',f2);require('shelljs').sed('-i',/^declare module '(\\.[^']+)'/,'declare module \\'\\$1.mjs\\'',f2)})\"",
"patch-readme": "shx sed -i 's/.*Jotai \\(dark mode\\).*//' dist/readme.md"
"patch-readme": "shx sed -i 's/.*Jotai \\(dark mode\\).*//' dist/readme.md",
"benchmarks": "pnpm run --parallel '/^benchmark:.*/'",
"benchmark:read": "tsx benchmarks/simple-read.ts",
"benchmark:write": "tsx benchmarks/simple-write.ts",
"benchmark:subscribe-write": "tsx benchmarks/subscribe-write.ts"
},
"engines": {
"node": ">=12.20.0"
Expand Down Expand Up @@ -184,5 +188,8 @@
"react": {
"optional": true
}
},
"dependencies": {
"tsx": "^4.16.2"
}
}
49 changes: 19 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b00afe2

Please sign in to comment.