{"id":17657968,"url":"https://github.com/3rd/benchmate","last_synced_at":"2025-05-07T11:46:45.853Z","repository":{"id":181511507,"uuid":"655758288","full_name":"3rd/benchmate","owner":"3rd","description":"Small but mighty benchmarking library for JavaScript","archived":false,"fork":false,"pushed_at":"2024-12-21T22:02:20.000Z","size":318,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T04:35:44.276Z","etag":null,"topics":["benchmark","javascript","performance","typescript"],"latest_commit_sha":null,"homepage":"","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/3rd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-19T14:35:20.000Z","updated_at":"2025-03-20T04:30:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"ea1682b5-385a-4f9f-9615-2fa316cba274","html_url":"https://github.com/3rd/benchmate","commit_stats":null,"previous_names":["3rd/benchmate"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fbenchmate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fbenchmate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fbenchmate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3rd%2Fbenchmate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3rd","download_url":"https://codeload.github.com/3rd/benchmate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873938,"owners_count":21817708,"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","javascript","performance","typescript"],"created_at":"2024-10-23T14:43:48.956Z","updated_at":"2025-05-07T11:46:45.833Z","avatar_url":"https://github.com/3rd.png","language":"TypeScript","readme":"# benchmate\n\nBenchmate is a small but mighty benchmarking library for JavaScript.\n\n- Comes with sensible defaults and tries to figure out the best parameters on its own.\n- Supports duration and iteration count targeting.\n- Works with both `process.hrtime` and `performance.now`.\n- Has hooks for `setup` and `teardown` (before and after the entire test, not each execution).\n- Has `async` support, but you really shouldn't benchmark async functions.\n- Returns the metrics and prints the output nicely (optional).\n\n## Demo\n\n[![benchmate on asciicast](https://asciinema.org/a/TCvVvn8qELEeQpflETsnoj64C.svg)](https://asciinema.org/a/TCvVvn8qELEeQpflETsnoj64C)\n\n## Installation\n\nBenchmate is published on the NPM registry: [https://npmjs.com/package/benchmate](https://npmjs.com/package/benchmate)\n\n```sh\nnpm install -D benchmate\npnpm install -D benchmate\nyarn add -D benchmate\n```\n\n## Usage\n\n**Notes:**\n\n- **Don't disable batching** if you want accurate measurements. Metrics like `min`, `max`, and percentiles will me meaningless, as you get a single measurement.\n- **Don't expect accurate timings for fast async functions**, but you can compare their performance.\n\n```ts\nimport { Bench } from \"benchmate\";\n\n// The default options are sensible,\nconst bench = new Bench({\n  iterations: \"auto\", // number of iterations, must be \"auto\" when using time ╷\n  time: 1000, // target running time for tasks                              ⮜─╯\n  batching: { // batching improves accuracy by a \u003clot\u003e\n    enabled: true,\n    size: \"auto\" // number of iterations per batch or \"auto\"\n  },\n  warmup: {\n    enabled: true,\n    size: \"auto\", // number of warmup iterations or \"auto\" for (iterations / 10)\n  },\n  method: \"auto\", // \"auto\" | \"hrtime\" | \"performance.now\" - measurement method, defaults to best available\n  testSleepDuration: 0, // how long to sleep between tasks (ms)\n  quiet: false, // don't print anything, defaults to `true` in browsers, `false` in Node\n  setup: () =\u003e Promise\u003cvoid\u003e | void, // function to run before each test\n  teardown: () =\u003e Promise\u003cvoid\u003e | void, // function to run after each test\n});\n\nbench.add(\"RegExp#test\", () =\u003e {\n  if (!/o/.test(\"Hello World!\")) console.log(\"nop\");\n});\n\nbench.add(\"String#indexOf\", () =\u003e {\n  if (\"Hello World!\".indexOf(\"o\") === -1) console.log(\"nop\");\n});\n\nawait bench.run();\n// ^ returns an array of benchmark results:\n// type BenchmarkResult = {\n//   name: string;\n//   stats: {\n//     samples: number;\n//     batches: number;\n//     time: { // all timings are in milliseconds\n//       total: number;\n//       min: number;\n//       max: number;\n//       average: number;\n//       percentile50: number;\n//       percentile90: number;\n//       percentile95: number;\n//     };\n//     opsPerSecond: {\n//       average: number;\n//       max: number;\n//       min: number;\n//       margin: number; // percentage\n//     };\n```\n\n## Acknowledgements\n\n- [Mathias Bynens](https://mathiasbynens.be) and [Benchmark.js](https://github.com/bestiejs/benchmark.js)\n- [mitata](https://github.com/evanwashere/mitata)\n- [tinybench](https://github.com/tinylibs/tinybench)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fbenchmate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3rd%2Fbenchmate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3rd%2Fbenchmate/lists"}