{"id":13484919,"url":"https://github.com/tinylibs/tinybench","last_synced_at":"2025-05-14T09:06:13.387Z","repository":{"id":57982338,"uuid":"519455224","full_name":"tinylibs/tinybench","owner":"tinylibs","description":"🔎 A simple, tiny and lightweight benchmarking library!","archived":false,"fork":false,"pushed_at":"2025-05-13T16:16:34.000Z","size":2665,"stargazers_count":2037,"open_issues_count":17,"forks_count":42,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-14T09:02:29.862Z","etag":null,"topics":["benchmark","hacktoberfest","light-weight","performance","tinylibs"],"latest_commit_sha":null,"homepage":"https://tinylibs.github.io/tinybench/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinylibs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"polar":"tinylibs"}},"created_at":"2022-07-30T07:57:59.000Z","updated_at":"2025-05-13T21:15:01.000Z","dependencies_parsed_at":"2024-02-03T10:23:41.631Z","dependency_job_id":"8d34e6d8-0eaf-4668-b3fe-e323b21176e8","html_url":"https://github.com/tinylibs/tinybench","commit_stats":{"total_commits":344,"total_committers":28,"mean_commits":"12.285714285714286","dds":0.5697674418604651,"last_synced_commit":"8a6975db6e74de1133e398dcf07fca1aae690862"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylibs%2Ftinybench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylibs%2Ftinybench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylibs%2Ftinybench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinylibs%2Ftinybench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinylibs","download_url":"https://codeload.github.com/tinylibs/tinybench/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110373,"owners_count":22016391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","hacktoberfest","light-weight","performance","tinylibs"],"created_at":"2024-07-31T17:01:38.842Z","updated_at":"2025-05-14T09:06:13.319Z","avatar_url":"https://github.com/tinylibs.png","language":"TypeScript","funding_links":["https://polar.sh/tinylibs"],"categories":["TypeScript"],"sub_categories":[],"readme":"# Tinybench 🔎\n\n[![CI](https://github.com/tinylibs/tinybench/actions/workflows/qa.yml/badge.svg?branch=main)](https://github.com/tinylibs/tinybench/actions/workflows/qa.yml)\n[![NPM version](https://badgen.net/npm/v/tinybench?icon=npm)](https://www.npmjs.com/package/tinybench)\n[![Discord](https://badgen.net/discord/online-members/c3UUYNcHrU?icon=discord\u0026label=discord\u0026color=green)](https://discord.gg/c3UUYNcHrU)\n[![neostandard Javascript Code Style](\u003chttps://badgen.net/static/code style/neostandard/green\u003e)](https://github.com/neostandard/neostandard)\n\nBenchmark your code easily with Tinybench, a simple, tiny and light-weight `10KB` (`2KB` minified and gzipped) benchmarking library!\nYou can run your benchmarks in multiple JavaScript runtimes, Tinybench is completely based on the Web APIs with proper timing using\n`process.hrtime` or `performance.now`.\n\n- Accurate and precise timing based on the environment\n- Statistically analyzed latency and throughput values: standard deviation, margin of error, variance, percentiles, etc.\n- Concurrency support\n- `Event` and `EventTarget` compatible events\n- No dependencies\n\n_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_\n\n## Installing\n\n```shell\n$ npm install -D tinybench\n```\n\n## Usage\n\nYou can start benchmarking by instantiating the `Bench` class and adding benchmark tasks to it.\n\n```js\nimport { Bench } from 'tinybench'\n\nconst bench = new Bench({ name: 'simple benchmark', time: 100 })\n\nbench\n  .add('faster task', () =\u003e {\n    console.log('I am faster')\n  })\n  .add('slower task', async () =\u003e {\n    await new Promise(resolve =\u003e setTimeout(resolve, 1)) // we wait 1ms :)\n    console.log('I am slower')\n  })\n\nawait bench.run()\n\nconsole.log(bench.name)\nconsole.table(bench.table())\n\n// Output:\n// simple benchmark\n// ┌─────────┬───────────────┬───────────────────┬───────────────────────┬────────────────────────┬────────────────────────┬─────────┐\n// │ (index) │ Task name     │ Latency avg (ns)  │ Latency med (ns)      │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │\n// ├─────────┼───────────────┼───────────────────┼───────────────────────┼────────────────────────┼────────────────────────┼─────────┤\n// │ 0       │ 'faster task' │ '63768 ± 4.02%'   │ '58954 ± 15255.00'    │ '18562 ± 1.67%'        │ '16962 ± 4849'         │ 1569    │\n// │ 1       │ 'slower task' │ '1542543 ± 7.14%' │ '1652502 ± 167851.00' │ '808 ± 19.65%'         │ '605 ± 67'             │ 65      │\n// └─────────┴───────────────┴───────────────────┴───────────────────────┴────────────────────────┴────────────────────────┴─────────┘\n```\n\nThe `add` method accepts a task name and a task function, so it can benchmark\nit! This method returns a reference to the Bench instance, so it's possible to\nuse it to create an another task for that instance.\n\nNote that the task name should always be unique in an instance, because Tinybench stores the tasks based\non their names in a `Map`.\n\nAlso note that `tinybench` does not log any result by default. You can extract the relevant stats\nfrom `bench.tasks` or any other API after running the benchmark, and process them however you want.\n\nMore usage examples can be found in the [examples](./examples/) directory.\n\n## Docs\n\n### [`Bench`](https://tinylibs.github.io/tinybench/classes/Bench.html)\n\n### [`Task`](https://tinylibs.github.io/tinybench/classes/Task.html)\n\n### [`TaskResult`](https://tinylibs.github.io/tinybench/interfaces/TaskResult.html)\n\n### `Events`\n\nBoth the `Task` and `Bench` classes extend the `EventTarget` object. So you can attach listeners to different types of events in each class instance using the universal `addEventListener` and `removeEventListener` methods.\n\n#### [`BenchEvents`](https://tinylibs.github.io/tinybench/types/BenchEvents.html)\n\n```js\n// runs on each benchmark task's cycle\nbench.addEventListener('cycle', (evt) =\u003e {\n  const task = evt.task!;\n});\n```\n\n#### [`TaskEvents`](https://tinylibs.github.io/tinybench/types/TaskEvents.html)\n\n```js\n// runs only on this benchmark task's cycle\ntask.addEventListener('cycle', (evt) =\u003e {\n  const task = evt.task!;\n});\n```\n\n### [`BenchEvent`](https://tinylibs.github.io/tinybench/types/BenchEvent.html)\n\n## `process.hrtime`\n\nif you want more accurate results for nodejs with `process.hrtime`, then import\nthe `hrtimeNow` function from the library and pass it to the `Bench` options.\n\n```ts\nimport { hrtimeNow } from 'tinybench'\n```\n\nIt may make your benchmarks slower.\n\n## Concurrency\n\n- When `mode` is set to `null` (default), concurrency is disabled.\n- When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.\n- When `mode` is set to 'bench', different tasks within the bench run concurrently. Concurrent cycles.\n\n```ts\nbench.threshold = 10 // The maximum number of concurrent tasks to run. Defaults to Number.POSITIVE_INFINITY.\nbench.concurrency = 'task' // The concurrency mode to determine how tasks are run.\nawait bench.run()\n```\n\n## Prior art\n\n- [Benchmark.js](https://github.com/bestiejs/benchmark.js)\n- [mitata](https://github.com/evanwashere/mitata/)\n- [tatami-ng](https://github.com/poolifier/tatami-ng)\n- [Bema](https://github.com/prisma-labs/bema)\n\n## Authors\n\n| \u003ca href=\"https://github.com/Aslemammad\"\u003e \u003cimg width='150' src=\"https://avatars.githubusercontent.com/u/37929992?v=4\" /\u003e\u003cbr\u003e Mohammad Bagher \u003c/a\u003e |\n| ------------------------------------------------------------------------------------------------------------------------------------------------ |\n\n## Credits\n\n| \u003ca href=\"https://github.com/uzlopak\"\u003e \u003cimg width='150' src=\"https://avatars.githubusercontent.com/u/5059100?v=4\" /\u003e\u003cbr\u003e Uzlopak \u003c/a\u003e | \u003ca href=\"https://github.com/poyoho\"\u003e \u003cimg width='150' src=\"https://avatars.githubusercontent.com/u/36070057?v=4\" /\u003e\u003cbr\u003e poyoho \u003c/a\u003e |\n| ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |\n\n## Contributing\n\nFeel free to create issues/discussions and then PRs for the project!\n\n## Sponsors\n\nYour sponsorship can make a huge difference in continuing our work in open source!\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg\"\u003e\n    \u003cimg src='https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg'/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinylibs%2Ftinybench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinylibs%2Ftinybench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinylibs%2Ftinybench/lists"}