Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run benchmarks using tinybench and CodSpeed #404

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@ jobs:
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: "npm"
- name: Install dependencies
run: npm install --ignore-scripts --no-audit --no-fund
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: npm run benchmark
26 changes: 26 additions & 0 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Bench } from "tinybench"
import { withCodSpeed } from "@codspeed/tinybench-plugin"
import * as fs from "fs"
import { analyze } from '../src/index.js'

let filelist = fs.readdirSync('./src/__fixtures__')
let files = filelist
.filter(filename => filename.endsWith('.css'))
.filter(filename => filename.includes('css-tricks'))
.reduce((acc, filename) => {
let css = fs.readFileSync(`./src/__fixtures__/${filename}`, 'utf8')
acc.set(filename, css)
return acc
}, new Map())

let bench = withCodSpeed(new Bench())

for (let [filename, css] of files) {
let byte_size = (Buffer.byteLength(css) / 1024).toFixed(1)
bench.add(`${filename} (${byte_size}kB)`, () => analyze(css))
}

await bench.warmup()
await bench.run()

console.table(bench.table())
19 changes: 0 additions & 19 deletions benchmark/format-filesize.js

This file was deleted.

36 changes: 0 additions & 36 deletions benchmark/parse-analyze-ratio.js

This file was deleted.

33 changes: 0 additions & 33 deletions benchmark/readme.md

This file was deleted.

72 changes: 0 additions & 72 deletions benchmark/run.js

This file was deleted.

Loading