MCPcopy Create free account
hub / github.com/sindresorhus/query-string / defineTestCase

Function defineTestCase

benchmark.js:27–49  ·  view source on GitHub ↗
(methodName, input, options)

Source from the content-addressed store, hash-verified

25
26// Creates a test case and adds it to the suite
27const defineTestCase = (methodName, input, options) => {
28 const function_ = queryString[methodName];
29 const label = options ? ` (${stringify(options)})` : '';
30 const expected = function_(input, options || {});
31 // `extract` is far cheaper than the other methods, so it needs more operations per sample.
32 const operations = methodName === 'extract' ? 1_000_000 : 10_000;
33
34 bench(methodName + label, b => {
35 const results = [];
36
37 b.start();
38 for (let index = 0; index < operations; index++) {
39 results.push(function_(input, options || {}));
40 }
41
42 b.end(operations);
43
44 // Validated outside the measured region, so the results are observable and the work cannot be eliminated.
45 for (const result of results) {
46 assert.deepEqual(result, expected);
47 }
48 });
49};
50
51// Define all test cases
52suite('query-string', () => {

Callers 1

benchmark.jsFile · 0.85

Calls 1

stringifyFunction · 0.85

Tested by

no test coverage detected