(fn, minDurationSeconds)
| 958 | } |
| 959 | |
| 960 | function benchmark(fn, minDurationSeconds) { |
| 961 | fn(); |
| 962 | let batchSize = 1; |
| 963 | while (batchSize < 1_000_000) { |
| 964 | const elapsed = measureBatch(fn, batchSize); |
| 965 | if (elapsed >= 10_000_000n) { |
| 966 | break; |
| 967 | } |
| 968 | batchSize *= 2; |
| 969 | } |
| 970 | |
| 971 | const targetNs = BigInt(Math.floor(minDurationSeconds * 1e9)); |
| 972 | let totalElapsed = 0n; |
| 973 | let totalIterations = 0; |
| 974 | |
| 975 | while (totalElapsed < targetNs) { |
| 976 | const elapsed = measureBatch(fn, batchSize); |
| 977 | totalElapsed += elapsed; |
| 978 | totalIterations += batchSize; |
| 979 | } |
| 980 | |
| 981 | return Number(totalElapsed) / totalIterations; |
| 982 | } |
| 983 | |
| 984 | function buildResults(datasets, options) { |
| 985 | const benchmarks = []; |
no test coverage detected