Skip to content

Commit

Permalink
feat(delme): v13
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwlad90 committed Sep 27, 2024
1 parent ea5b944 commit 47665f8
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 18,753 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/NAPI-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ jobs:
# path: ${{ env.APP_NAME }}.*.node
# if-no-files-found: error
test-macOS-windows-binding:
if: false
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
Expand Down Expand Up @@ -416,7 +417,7 @@ jobs:
target: x86_64-apple-darwin
architecture: x64
node:
- '18'
# - '18'
- '20'
runs-on: ${{ matrix.settings.host }}
steps:
Expand Down Expand Up @@ -444,6 +445,11 @@ jobs:
with:
path: crates/stylex-rs-compiler/benchmark/results
key: ${{ matrix.settings.target }}-benchmark
- name: List packages
run: |
ls -R crates/stylex-rs-compiler/benchmark/results
cat crates/stylex-rs-compiler/benchmark/results/benchmark-data.json
shell: bash
- name: Run benchmarks
run: pnpm run --filter @stylexswc/rs-compiler bench
# - name: Store benchmark result
Expand All @@ -464,6 +470,12 @@ jobs:
external-data-json-path: 'crates/stylex-rs-compiler/benchmark/results/benchmark-data.json'
# Workflow will fail when an alert happens
fail-on-alert: true
comment-on-alert: true
alert-comment-cc-users: '@Dwlad90'
github-token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish:
name: Publish
runs-on: ubuntu-latest
Expand Down
12 changes: 12 additions & 0 deletions crates/stylex-rs-compiler/benchmark/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Benchmark from 'benchmark';
const suite = new Benchmark.Suite();

suite
.add('some test case', () => {
// ...
})
.on('cycle', event => {
// Output benchmark result by converting benchmark result to string
console.log(String(event.target));
})
.run();
46 changes: 14 additions & 32 deletions crates/stylex-rs-compiler/benchmark/bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bench } from 'tinybench'
import { Bench, Task } from 'tinybench'

import { transform } from '../dist/index.js'

Expand Down Expand Up @@ -42,46 +42,28 @@ const inputJsFiles = getInputJsFiles(stylexFixturePath)

inputJsFiles.forEach((file) => {
const content = fs.readFileSync(file, 'utf-8')
b.add(`Transform ${file}`, () => {
b.add(file.split('/').at(-2) ?? 'Default case', () => {
transform(file.replace('input.js', 'input.stylex.js'), content, stylexOptions)
})
})

const resultsDir = path.resolve(rootDir, 'benchmark/results')

if (!fs.existsSync(resultsDir)) {
fs.mkdirSync(resultsDir)
}

await b.warmup()
await b.run()

console.table(b.table())

console.table(b.table((task) => ({ 'Task name': task.name })))
const output = b.tasks.map(formatSummary).join('\n')

// Save benchmark results to a file
const resultsDir = path.resolve(rootDir, 'benchmark/results')
if (!fs.existsSync(resultsDir)) {
fs.mkdirSync(resultsDir)
}
fs.writeFileSync(path.join(resultsDir, 'output.txt'), output, 'utf8')
console.log('Benchmark results saved to benchmark/results/output.txt')

const results = b.tasks.map((task) => ({
name: task.name,
hz: task.result?.hz,
rme: task.result?.rme,
samples: task.result?.samples,
mean: task.result?.mean,
variance: task.result?.variance,
}))

const benchmarkjsResults = {
benchmarks: results.map(result => ({
name: result.name,
hz: result.hz,
rme: result.rme,
samples: result.samples,
stats: {
mean: result.mean,
variance: result.variance,
},
})),
function formatSummary(task: Task): string {
const { name, result } = task
return `${name} x ${(result?.hz || 0) * 1000} ops/sec ±${(result?.rme || 0) * 1000}% (${(result?.samples?.length ?? 0)} runs sampled)`
}

fs.writeFileSync(path.join(resultsDir, 'output.txt'), JSON.stringify(benchmarkjsResults, null, 2))

console.log('Benchmark results saved to benchmark/results/output.txt')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some test case x 1945,1724,1446 ops/sec ±5.18% (102 runs sampled)
Loading

0 comments on commit 47665f8

Please sign in to comment.