### Install Chūhai via npm Source: https://github.com/hypercubed/chuhai/blob/master/README.md Command to install Chūhai as a development dependency using npm. This makes the library available for use in your project's development environment. ```sh npm i --save-dev chuhai ``` -------------------------------- ### Chūhai `s.cycle` Function API Source: https://github.com/hypercubed/chuhai/blob/master/README.md Documents the `s.cycle` method, which defines a function to be executed between each benchmark run within a suite. This is typically used for assertion checks, setup, or teardown logic to ensure consistent test conditions and validate results. ```APIDOC // runs between benchmarks (place assertions checks here) s.cycle(implementation: function) ``` -------------------------------- ### Chūhai `suite` Function API Source: https://github.com/hypercubed/chuhai/blob/master/README.md Documents the `suite` function, which initializes a new benchmark suite. It can optionally take a title (string) and requires an implementation function. The function returns a promise, allowing for asynchronous handling of benchmark results. ```APIDOC // creates a new benchmark suite // returns a promise suite([title: string], implementation: function): promise ``` -------------------------------- ### Basic Chūhai Benchmark Suite with Node.js and Assert Source: https://github.com/hypercubed/chuhai/blob/master/README.md Demonstrates how to create a benchmark suite using Chūhai, `node-assert`, and Node.js. It defines a suite for array concatenation, includes a `cycle` function for assertions between benchmarks, and shows `burn` and `bench` methods for different types of performance tests. The suite returns a promise, suitable for modern async test runners. ```js var assert = require('assert'); var suite = require('chuhai'); // starts a new benchmark suite // note this returns a promise suite('array concat', function (s) { var arr1 = ['a', 'b', 'c']; var arr2 = ['d', 'e', 'f']; var arr3 = null; // run between each benchmark s.cycle(function () { // uses your assertion lib of choice assert.deepEqual(arr3, ['a', 'b', 'c', 'd', 'e', 'f']); arr3 = null; }); // adds a bench that runs but doesn't get counted when comparing results to others. s.burn('slice', function () { arr3 = ['a', 'b', 'c', 'd', 'e', 'f'].slice(); }); // adds a bench. s.bench('concat', function () { arr3 = arr1.concat(arr2); }); // adds a bench. s.bench('for loop', function () { var i; var l1 = arr1.length; var l2 = arr2.length; arr3 = Array(l1 + l2); for (i = 0; i < l1; i++) { arr3[i] = arr1[i]; } for (var i2 = 0; i2 < l2; i2++) { arr3[i + i2] = arr2[i2]; } }); }); ``` -------------------------------- ### Run Chūhai Benchmark File Source: https://github.com/hypercubed/chuhai/blob/master/README.md Command to execute the Chūhai benchmark file using Node.js. This assumes the benchmark file is named `bench.js` and is located in the current directory. ```sh node bench.js ``` -------------------------------- ### Chūhai `s.set` Function API Source: https://github.com/hypercubed/chuhai/blob/master/README.md Documents the `s.set` method, used to configure options for the current benchmark or the entire suite. It takes a `key` (string) representing the option name and a `value` (any type) to set for that option. ```APIDOC // sets benchmark/suite options s.set(key: string, value: any) ``` -------------------------------- ### Chūhai `s.bench` Function API Source: https://github.com/hypercubed/chuhai/blob/master/README.md Documents the `s.bench` method, used within a suite's implementation function to define a standard benchmark test. It takes a title (string) for identification and an implementation function containing the code to be benchmarked. ```APIDOC // creates a new benchmark test s.bench(title: string, implementation: function) ``` -------------------------------- ### Chūhai `s.burn` Function API Source: https://github.com/hypercubed/chuhai/blob/master/README.md Documents the `s.burn` method, used within a suite to define a 'burn-in' benchmark test. These tests run but their results are not included when comparing performance against other benchmarks in the suite. It takes a title (string) and an implementation function. ```APIDOC // creates a burn-in benchmark test s.burn(title: string, implementation: function) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.