{"id":13432618,"url":"https://github.com/Hypercubed/chuhai","last_synced_at":"2025-03-17T10:32:20.101Z","repository":{"id":66193244,"uuid":"59404640","full_name":"Hypercubed/chuhai","owner":"Hypercubed","description":"Test driven benchmarking.","archived":false,"fork":false,"pushed_at":"2018-08-12T04:46:16.000Z","size":44,"stargazers_count":88,"open_issues_count":1,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-11T08:08:36.643Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hypercubed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-05-22T09:33:32.000Z","updated_at":"2021-09-07T15:58:54.000Z","dependencies_parsed_at":"2023-04-20T14:32:59.275Z","dependency_job_id":null,"html_url":"https://github.com/Hypercubed/chuhai","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fchuhai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fchuhai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fchuhai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2Fchuhai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hypercubed","download_url":"https://codeload.github.com/Hypercubed/chuhai/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244016780,"owners_count":20384203,"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":[],"created_at":"2024-07-31T02:01:14.282Z","updated_at":"2025-03-17T10:32:19.604Z","avatar_url":"https://github.com/Hypercubed.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Works with AVA"],"sub_categories":[],"readme":"# Chūhai\n\nTest driven benchmarking.\n\n[![version](https://img.shields.io/npm/v/chuhai.svg)](https://www.npmjs.org/package/chuhai)\n[![status](https://travis-ci.org/Hypercubed/chuhai.svg)](https://travis-ci.org/Hypercubed/chuhai)\n[![coverage](https://img.shields.io/coveralls/Hypercubed/chuhai.svg)](https://coveralls.io/github/Hypercubed/chuhai)\n[![dependencies](https://david-dm.org/Hypercubed/chuhai.svg)](https://david-dm.org/Hypercubed/chuhai)\n[![devDependencies](https://david-dm.org/Hypercubed/chuhai/dev-status.svg)](https://david-dm.org/Hypercubed/chuhai#info=devDependencies)\n![node](https://img.shields.io/node/v/chuhai.svg)\n\n## Why Chūhai?\n\nWhat's more useless than micro-benchmarks micro-optimization?  Micro-benchmarks without tests to ensure they are doing what you think they are doing.  I've seen it more that once.  I've done it many times myself.  Chūhai is my attempt to fix that by combining testing and benchmarks.\n\n*Read the [FAQ](https://github.com/Hypercubed/chuhai/wiki/FAQ) for more information*\n\n## Features\n\n* Runs alongside multiple assertion libraries and test runners (see [Test runners/Assertion libraries] below).\n* Runs in the browser (see [Test runners/Assertion libraries] below).\n* By default returns a promise (good for node-tap, blue-tape, and AVA)\n* Supports callbacks (good for tape)\n* No magic globals means no required runner.\n* more...\n\n## Install\n\n```sh\nnpm i --save-dev chuhai\n```\n\n## Usage\n\nCreate a file named bench.js:\n\n**example using node and assert, see below for other setups**\n\n```js\nvar assert = require('assert');\nvar suite = require('chuhai');\n\n// starts a new benchmark suite\n// note this returns a promise\nsuite('array concat', function (s) {\n  var arr1 = ['a', 'b', 'c'];\n  var arr2 = ['d', 'e', 'f'];\n  var arr3 = null;\n\n  // run between each benchmark\n  s.cycle(function () {\n    // uses your assertion lib of choice\n    assert.deepEqual(arr3, ['a', 'b', 'c', 'd', 'e', 'f']);\n    arr3 = null;\n  });\n\n  // adds a bench that runs but doesn't get counted when comparing results to others.\n  s.burn('slice', function () {\n    arr3 = ['a', 'b', 'c', 'd', 'e', 'f'].slice();\n  });\n\n  // adds a bench.\n  s.bench('concat', function () {\n    arr3 = arr1.concat(arr2);\n  });\n\n  // adds a bench.\n  s.bench('for loop', function () {\n    var i;\n    var l1 = arr1.length;\n    var l2 = arr2.length;\n    arr3 = Array(l1 + l2);\n    for (i = 0; i \u003c l1; i++) {\n      arr3[i] = arr1[i];\n    }\n    for (var i2 = 0; i2 \u003c l2; i2++) {\n      arr3[i + i2] = arr2[i2];\n    }\n  });\n});\n```\n\nRun using node, tap, babel-node, or tape\n\n* AVA requires you to use the AVA API *\n\n```sh\nnode bench.js\n```\n\n## Test runners/Assertion libraries\n\nChūhai is designed to work well with test runners and assertion libraries such as:\n\n- [node-assert](https://nodejs.org/api/assert.html) - [example](./test/fixtures/assert)\n- [tapjs/node-tap](https://github.com/tapjs/node-tap)\n- [avajs/ava](https://github.com/avajs/ava) - [example](./test/fixtures/ava)\n- [substack/tape](https://github.com/substack/tape) - [example](./test/fixtures/tape)\n- [spion/blue-tape](https://github.com/spion/blue-tape) - [example](./test/fixtures/bluetape)\n\nas well as in-browser runners such as (combined with  [substack/node-browserify](https://github.com/substack/node-browserify)):\n\n- [substack/testling](https://github.com/substack/testling) - [example](https://github.com/Hypercubed/chuhai/blob/master/package.json#L12)\n- [juliangruber/tape-run](https://github.com/juliangruber/tape-run) - [example](https://github.com/Hypercubed/chuhai/blob/dev/package.json#L12)\n\nalso works well with:\n\n- [Hypercubed/grunion](https://github.com/Hypercubed/grunion)\n- [zoubin/tap-summary](https://github.com/zoubin/tap-summary)\n- [Hypercubed/tap-markdown](https://github.com/Hypercubed/tap-markdown)\n\n*At this time I recommend blue-tape and testling if you plan to run benchmarks in the browser, otherwise AVA.*\n\n**More details coming soon**\n\n## API\n\n```js\n// creates a new benchmark suite\n// returns a promise\nsuite([title: string], implementation: function): promise\n```\n\n### function implementation(s) {}\n\n```js\n// creates a new benchmark test\ns.bench(title: string, implementation: function)\n```\n\n```js\n// creates a burn-in benchmark test\ns.burn(title: string, implementation: function)\n```\n\n```js\n// runs between benchmarks (place assertions checks here)\ns.cycle(implementation: function)\n```\n\n```js\n// sets benchmark/suite options\ns.set(key: string, value: any)\n```\n\n## Acknowledgments\n\n[matcha](https://github.com/logicalparadox/matcha) inspired the tool.  [AVA](https://github.com/avajs/ava) and [TAPE](https://github.com/substack/tape) inspired the syntax.  [benchmark.js](https://github.com/bestiejs/benchmark.js) made it possible.\n\n## License\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n\nCopyright (c) 2016 Jayson Harshbarger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHypercubed%2Fchuhai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHypercubed%2Fchuhai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHypercubed%2Fchuhai/lists"}