20 lines
444 B
JavaScript
20 lines
444 B
JavaScript
import { BenchmarkType } from './Benchmark.js'
|
|
|
|
export class OpsPerTimeBenchmark extends BenchmarkType {
|
|
constructor(timeToRun) {
|
|
super()
|
|
this.timeToRun = timeToRun
|
|
}
|
|
|
|
async measure() {
|
|
let start = performance.now()
|
|
let iterations = 0
|
|
while (performance.now() - start < this.timeToRun) {
|
|
iterations++
|
|
await this.case.fn()
|
|
}
|
|
let stop = performance.now()
|
|
return (stop - start) / iterations
|
|
}
|
|
}
|