-
Notifications
You must be signed in to change notification settings - Fork 35
chore: fix calculation of average in benchmark #1243
Conversation
export const timeFunction = async (func, runs = 1) => { | ||
const finishedRuns = new Map() | ||
|
||
performance.clearMarks() | ||
performance.clearMeasures() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strictly necessary but if we run multiple benchmarks after each other, this is critical. Anyway it doesn't hurt.
await Promise.all( | ||
Array.from({ length: runs }).map(async (_, index) => { | ||
performance.mark(`run-${index}-start`) | ||
for (let index = 0; index < runs; index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use for loop so that the runs are not running in parallel, which I guess where the reason for the change in the timings here in the github action.
β± Benchmark resultsComparing with 53d6526 largeDepsEsbuild: 2.3sβ¬οΈ 106.94% decrease vs. 53d6526
LegendlargeDepsNft: 10.8sβ¬οΈ 135.52% decrease vs. 53d6526
LegendlargeDepsZisi: 15.9sβ¬οΈ 12.68% decrease vs. 53d6526
|
}), | ||
) | ||
// wait for PerformanceObserver to gather all data | ||
await sleep(100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the PerformanceObserver is triggered async, we need to wait till it was triggered.
Right now out of the 3 runs we usually only calculate the average with the numbers of 2 runs but divide it by 3. So the number is completely off.
The assert a little down is also there to ensure we captured all runs.
|
||
const durations = [...finishedRuns.values()] | ||
|
||
observer.disconnect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disconnect it, just in the case we run multiple benchmarks, so that we do not have multiple observers observing.
Summary
See inline comments
For us to review and ship your PR efficiently, please perform the following steps:
This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing
a typo or something that`s on fire π₯ (e.g. incident related), you can skip this step.
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)