Skip to content

Commit

Permalink
Run benchmarks using tinybench and CodSpeed (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman authored Jul 3, 2024
1 parent aaf0a1f commit 92ce554
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 161 deletions.
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

0 comments on commit 92ce554

Please sign in to comment.