Skip to content

Commit

Permalink
chore: add benchmark (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jul 12, 2022
1 parent 002aaa9 commit 2addff1
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dist
lib
CHANGELOG.md
/pnpm-*.yaml
!/.github
!/.*.cjs
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"rules": {
"react/react-in-jsx-scope": "off"
}
},
{
"files": ".github/*.yml",
"rules": {
"unicorn/filename-case": "off"
}
}
]
}
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ jobs:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true

- name: Benchmark
run: node benchmark
if: matrix.node != 14

- name: Codecov
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
# eslint-disable-next-line yml/no-empty-mapping-value
pull_request:

jobs:
Expand Down
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ lib
LICENSE
*.json
*.log
*.txt
*.yaml
*.yml
11 changes: 11 additions & 0 deletions benchmark/benchmark.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cpu: Apple M1 Max
runtime: node v16.15.1 (arm64-darwin)

benchmark time (avg) (min … max) p75 p99 p995
-------------------------------------------------------- -----------------------------
yocto-ttl-cache 34.7 µs/iter (30.92 µs … 650.58 µs) 33.58 µs 84.79 µs 95.29 µs
@isaacs/ttlcache 114.71 µs/iter (99.75 µs … 3.53 ms) 108.71 µs 289.75 µs 714.38 µs

summary
yocto-ttl-cache
3.31x faster than @isaacs/ttlcache
26 changes: 26 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-check

import { run, bench, baseline } from 'mitata'

baseline('yocto-ttl-cache', async () => {
const { TTLCache } = await import('../lib/index.js')
const cache = new TTLCache(1)
cache.get('key')
cache.get('key', () => 'value')
cache.set('key', 'newValue')
})

bench('@isaacs/ttlcache', async () => {
const { default: TTLCache } = await import('@isaacs/ttlcache')
const cache = new TTLCache({ ttl: 1 })
cache.get('key')
cache.set('key', 'value')
// eslint-disable-next-line sonarjs/no-element-overwrite
cache.set('key', 'newValue')
})

await run({
colors: !['1', 'true'].includes(
/** @type {string} */ (process.env.NO_COLOR?.toLowerCase()),
),
})
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"!**/*.tsbuildinfo"
],
"scripts": {
"benchmark": "NO_COLOR=1 node benchmark > benchmark/benchmark.txt",
"build": "run-p build:*",
"build:r": "r -f cjs",
"build:ts": "tsc -p src",
Expand All @@ -79,6 +80,7 @@
"@1stg/lib-config": "^8.1.1",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.1",
"@isaacs/ttlcache": "^1.1.0",
"@pkgr/webpack": "^3.1.2",
"@pkgr/webpack-mdx": "^2.0.3",
"@size-limit/preset-small-lib": "^7.0.8",
Expand All @@ -90,6 +92,7 @@
"@types/web": "^0.0.69",
"github-markdown-css": "^5.1.0",
"jest-environment-jsdom": "^28.1.2",
"mitata": "^0.1.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
Expand Down
19 changes: 19 additions & 0 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 2addff1

Please sign in to comment.