Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

chore: fix calculation of average in benchmark #1243

Merged
merged 1 commit into from
Nov 2, 2022
Merged

chore: fix calculation of average in benchmark #1243

merged 1 commit into from
Nov 2, 2022

Conversation

danez
Copy link
Contributor

@danez danez commented Oct 31, 2022

Summary

See inline comments


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code πŸ§‘β€πŸ’».
    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.
  • Read the contribution guidelines πŸ“–. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) πŸ§ͺ
  • Update or add documentation (if features were changed or added) πŸ“
  • Make sure the status checks below are successful βœ…

A picture of a cute animal (not mandatory, but encouraged)

@danez danez self-assigned this Oct 31, 2022
export const timeFunction = async (func, runs = 1) => {
const finishedRuns = new Map()

performance.clearMarks()
performance.clearMeasures()
Copy link
Contributor Author

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++) {
Copy link
Contributor Author

@danez danez Oct 31, 2022

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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2022

⏱ Benchmark results

Comparing with 53d6526

largeDepsEsbuild: 2.3s

⬇️ 106.94% decrease vs. 53d6526

^   5.2s                                                                                  
β”‚   β”Œβ”€β”€β”                                                                                  
β”‚   |  |                                            4.8s                    4.7s          
β”‚   |  |                                            β”Œβ”€β”€β”                    β”Œβ”€β”€β”          
β”‚   |  |                                            |  |                    |  |          
β”‚   |  |    3.8s    3.9s    3.9s    3.8s    3.8s    |  |            3.8s    |  |          
β”‚ β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€β”€3.6sβ”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    β”Œβ”€β”€β”    |  |    |  |          
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    2.3s  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    β”Œβ”€β”€β”  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

largeDepsNft: 10.8s

⬇️ 135.52% decrease vs. 53d6526

^   27s                                                                                   
β”‚   β”Œβ”€β”€β”                                            25s                    25.5s          
β”‚   |  |                                            β”Œβ”€β”€β”                    β”Œβ”€β”€β”          
β”‚   |  |                                            |  |                    |  |          
β”‚   |  |                                            |  |                    |  |          
β”‚   |  |                                            |  |                    |  |          
β”‚   |  |                   19.4s                    |  |   18.5s   19.3s    |  |          
β”‚ ──┼──┼───17.6sβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€17.8s────18sβ”€β”€β”€β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Œβ”€β”€β”β”€β”€β”€β”€β”Όβ”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   |  |    β”Œβ”€β”€β”            |  |    β”Œβ”€β”€β”    β”Œβ”€β”€β”    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |            |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |            |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |            |  |    |  |    |  |    |  |    |  |    |  |    |  |          
β”‚   |  |    |  |            |  |    |  |    |  |    |  |    |  |    |  |    |  |   10.8s  
β”‚   |  |    |  |    9.7s    |  |    |  |    |  |    |  |    |  |    |  |    |  |    β”Œβ”€β”€β”  
β”‚   |  |    |  |    β”Œβ”€β”€β”    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

largeDepsZisi: 15.9s

⬇️ 12.68% decrease vs. 53d6526

^  37.8s                                                                                  
β”‚   β”Œβ”€β”€β”                                                                                  
β”‚   |  |                                           34.6s                                  
β”‚   |  |                                            β”Œβ”€β”€β”                                  
β”‚   |  |           29.6s                            |  |                                  
β”‚   |  |   27.5s    β”Œβ”€β”€β”           27.9s   27.9s    |  |   28.3s   29.2s                  
β”‚   |  |    β”Œβ”€β”€β”    |  |            β”Œβ”€β”€β”    β”Œβ”€β”€β”    |  |    β”Œβ”€β”€β”    β”Œβ”€β”€β”                  
β”‚ ──┼──┼────┼──┼────┼──┼────────────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼──────────────────
β”‚   |  |    |  |    |  |            |  |    |  |    |  |    |  |    |  |                  
β”‚   |  |    |  |    |  |            |  |    |  |    |  |    |  |    |  |                  
β”‚   |  |    |  |    |  |            |  |    |  |    |  |    |  |    |  |                  
β”‚   |  |    |  |    |  |            |  |    |  |    |  |    |  |    |  |   17.9s          
β”‚   |  |    |  |    |  |   14.7s    |  |    |  |    |  |    |  |    |  |    β”Œβ”€β”€β”   15.9s  
β”‚   |  |    |  |    |  |    β”Œβ”€β”€β”    |  |    |  |    |  |    |  |    |  |    |  |    β”Œβ”€β”€β”  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
β”‚   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |β–’β–’|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

}),
)
// wait for PerformanceObserver to gather all data
await sleep(100)
Copy link
Contributor Author

@danez danez Oct 31, 2022

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()
Copy link
Contributor Author

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.

@danez danez marked this pull request as ready for review October 31, 2022 14:40
@danez danez requested a review from a team October 31, 2022 14:40
@danez danez changed the title chore: fix benchmark chore: fix calculation of average in benchmark Oct 31, 2022
@danez danez merged commit 4587763 into main Nov 2, 2022
@danez danez deleted the benchmark branch November 2, 2022 09:00
Skn0tt pushed a commit to netlify/build that referenced this pull request May 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants