{"id":18665337,"url":"https://github.com/robertklep/node-benchr","last_synced_at":"2025-04-11T22:31:06.842Z","repository":{"id":35499918,"uuid":"39769650","full_name":"robertklep/node-benchr","owner":"robertklep","description":"Node.js benchmark runner","archived":false,"fork":false,"pushed_at":"2023-04-16T16:26:50.000Z","size":38,"stargazers_count":28,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T01:53:18.484Z","etag":null,"topics":["benchmark","node","node-benchmark-runner","performance-analysis"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/robertklep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2015-07-27T10:50:45.000Z","updated_at":"2025-03-14T03:49:03.000Z","dependencies_parsed_at":"2024-06-18T22:53:26.892Z","dependency_job_id":"2043eb2b-0133-42d9-a359-ca08d7dc43c9","html_url":"https://github.com/robertklep/node-benchr","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":0.02083333333333337,"last_synced_commit":"fe54379844b82de7cd064212f5fe35eecdf6ec3e"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fnode-benchr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fnode-benchr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fnode-benchr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fnode-benchr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertklep","download_url":"https://codeload.github.com/robertklep/node-benchr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248489550,"owners_count":21112600,"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","node","node-benchmark-runner","performance-analysis"],"created_at":"2024-11-07T08:27:16.145Z","updated_at":"2025-04-11T22:31:06.437Z","avatar_url":"https://github.com/robertklep.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## benchr\n\nNode.js benchmark runner, modelled after [`Mocha`](http://mochajs.org/) and [`bencha`](https://www.npmjs.com/package/bencha), based on [Benchmark.js](http://benchmarkjs.com/).\n\n### Installation\n\n```\n$ npm i benchr [-g]\n```\n\n### Usage\n\nRun the `benchr` script and provide it with files containing benchmarks:\n\n```\n$ benchr benchmarks/**/*.js\n$ benchr benchmarks/suite1.js benchmarks/suite2.js benchmarks/suite3.js\n```\n\n### Options\n\n```\n$ benchr -h\nbenchr – benchmark runner\n\nUsage:\n  benchr [options] \u003cfile\u003e...\n\nOptions:\n  -h --help                  Show this screen\n  -V --version               Show version\n  -d --delay=\u003cs\u003e             Delay between test cycles, in seconds       [default: 0]\n  -M --min-time=\u003cs\u003e          Minimum run time per test cycle, in seconds [default: 0]\n  -m --max-time=\u003cs\u003e          Maximum run time per test cycle, in seconds [default: 5]\n  -g --grep=\u003cs\u003e              Only run suites matching pattern\n  -R --reporter=\u003cname/file\u003e  Reporter to use, either a file path or built-in (`console` or `json`) [default: console]\n  -r --require=\u003cmodule\u003e      `require()` a module before starting (for instance, `babel-register`)\n  -p --progress              Show progress       (depending on reporter)\n  -P --pretty-print          Pretty-print output (depending on reporter)\n  -v --verbose               More verbose output (depending on reporter)\n```\n\n### Suites + benchmarks\n\nA benchmark file declares one or more suites, each with one or more benchmarks to run.\n\n#### Syntax\n\n```javascript\nsuite(NAME[, OPTIONS], FN);\nbenchmark(NAME[, OPTIONS], FN);\n```\n\nCalling `suite()` is optional.\n\n#### Synchronous benchmarks\n\n```javascript\nsuite('Finding a substring', () =\u003e {\n\n  benchmark('RegExp#test', () =\u003e {\n    /o/.test('Hello World!');\n  });\n\n  benchmark('String#indexOf', () =\u003e {\n    'Hello World!'.indexOf('o') \u003e -1;\n  });\n\n  benchmark('String#match', () =\u003e {\n    !!'Hello World!'.match(/o/);\n  });\n\n});\n```\n\n(taken from the example on the [Benchmark.js](http://benchmarkjs.com/) website)\n\n#### Asynchronous benchmarks\n\n##### Using promises\n\nReturn a promise from a benchmark function and it will be tested asynchronously:\n\n```javascript\nsuite('Timeouts', () =\u003e {\n\n  benchmark('100ms', () =\u003e {\n    return new Promise((resolve) =\u003e {\n      setTimeout(resolve, 100);\n    });\n  });\n\n  benchmark('200ms', () =\u003e {\n    return new Promise((resolve) =\u003e {\n      setTimeout(resolve, 200);\n    });\n  });\n\n});\n```\n\n**NOTE**: to determine if a function under test returns a promise, it is called once before the tests start. If this is undesirable, for instance due to side-effects, set the `promises` option for the benchmark or the entire suite:\n\n```javascript\nsuite('Timeouts',  { promises : true }, () =\u003e { ... });\nbenchmark('100ms', { promises : true }, () =\u003e { ... });\n```\n\n##### Using callbacks\n\nIf a benchmark takes an argument, it is assumed to be a continuation callback (pass any errors as first argument to abort the test):\n\n```javascript\nsuite('Timeouts', () =\u003e {\n\n  benchmark('100ms', (done) =\u003e {\n    setTimeout(done, 100);\n  });\n\n  benchmark('200ms', (done) =\u003e {\n    setTimeout(done, 200);\n  });\n\n});\n```\n\n#### Playing nice with linters\n\nTo work around linter errors regarding `suite` and `benchmark` being undefined, your test files can export a function that would take `suite` and `benchmark` as its arguments, thereby making the linter happy:\n\n```javascript\nmodule.exports = (suite, benchmark) =\u003e {\n  suite('My test suite', () =\u003e {\n    benchmark('Bench 1', ...);\n    benchmark('Bench 2', ...);\n    ...\n  })\n}\n```\n\n### Using the Runner programmatically\n\n```\nconst Runner = require('benchr');\nconst runner = new Runner({\n    reporter    : Function,\n    grep        : String,\n    delay       : Number,\n    minTime     : Number,\n    maxTime     : Number,\n    progress    : Boolean,\n    prettyPrint : Boolean,\n    verbose     : Boolean,\n}, [ \"file1.js\", \"file2.js\", ... ]);\n```\n\nAll options map to the similarly-named command line options.\n\n### Implementing a reporter\n\nA reporter is a CommonJS module that should export a function that gets passed a benchmark runner instance as argument.\n\nThis runner instance implements the `EventEmitter` interface, and will emit the following events:\n\n* `run.start` / `run.complete`\n* `file.start` / `file.complete`\n* `suite.start` / `suite.complete`\n* `benchmark.start` / `benchmark.complete`\n\nThe different parts are explained as follows:\n* a _\"run\"_ consists of one or more files containing benchmarks\n* a _\"file\"_ is a file that exports or contains one or more suites\n* a _\"suite\"_ is a structure that consists of one or more benchmarks (where each benchmark is used in a comparison between the other benchmarks in the same suite)\n* a _\"benchmark\"_ is a single test\n\n### TODO\n\n- [x] Option to pass custom reported module\n- [x] Before/after hooks\n- [x] Benchmark/suite options (minTime, maxTime, ...)\n- [x] Separate reporters (very hardcoded now)\n- [x] Handle multiple \"fastest\" benchmarks better\n- [x] Promises support (just like Mocha)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertklep%2Fnode-benchr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertklep%2Fnode-benchr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertklep%2Fnode-benchr/lists"}