| 25 | let TIMES_TO_RUN = 100_000; |
| 26 | |
| 27 | function testCase(name, fn) { |
| 28 | let result, error, time, total; |
| 29 | |
| 30 | try { |
| 31 | result = fn(); |
| 32 | } catch (thrownError) { |
| 33 | error = thrownError; |
| 34 | } |
| 35 | |
| 36 | if (!error) { |
| 37 | const start = process.hrtime(); |
| 38 | |
| 39 | for (let i = 0; i < TIMES_TO_RUN; i++) { |
| 40 | fn(); |
| 41 | } |
| 42 | |
| 43 | const diff = process.hrtime(start); |
| 44 | |
| 45 | total = diff[0] * 1e9 + diff[1]; |
| 46 | time = Math.round(total / TIMES_TO_RUN); |
| 47 | } |
| 48 | |
| 49 | return { |
| 50 | error, |
| 51 | name, |
| 52 | result, |
| 53 | time, |
| 54 | total, |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | function test(name, value, ignoreResult, prettyFormatOpts) { |
| 59 | const formatted = testCase('prettyFormat() ', () => |