(name: string, fn: () => void, iterations = 1000)
| 2 | import { Decimal } from 'decimal.js'; |
| 3 | |
| 4 | function bench(name: string, fn: () => void, iterations = 1000): string { |
| 5 | // Warmup |
| 6 | for (let i = 0; i < 10; i++) fn(); |
| 7 | |
| 8 | const start = performance.now(); |
| 9 | for (let i = 0; i < iterations; i++) fn(); |
| 10 | const elapsed = performance.now() - start; |
| 11 | const msPerOp = elapsed / iterations; |
| 12 | const line = ` ${name.padEnd(30)} ${msPerOp.toFixed(4)} ms/op (${iterations} iters)`; |
| 13 | console.log(line); |
| 14 | return line; |
| 15 | } |
| 16 | |
| 17 | console.log('BigDecimal vs Decimal.js Benchmarks'); |
| 18 | console.log('='.repeat(70)); |
no test coverage detected