| 25 | |
| 26 | // Creates a test case and adds it to the suite |
| 27 | const 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 |
| 52 | suite('query-string', () => { |