SlideShare a Scribd company logo
1 of 68
Using jsPerf correctly
@mathias – #jsconfeu 2011
<sup>
@mathias
jsPerf
jsPerf is 426 days old.
24,164 test cases → ~56.72 per day
83,536 tests → ~3.46 per test case
1,012 comments → ~2.38 per day
jsPerf is 426 days old.
24,164 test cases → ~56.72 per day
83,536 tests → ~3.46 per test case
1,012 comments → ~2.38 per day
“68% of all jsPerf test cases
        is broken.”
             — Jean-Jacques Rousseau
“It would be unwise to take
all jsPerf results for granted.”
                 — William Shakespeare
Benchmarking pitfalls




    “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
• Inaccurate millisecond timers




     “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
• Inaccurate millisecond timers
• Browser bugs




     “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
• Inaccurate millisecond timers
• Browser bugs
• No statistically significant results




     “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
•   Inaccurate millisecond timers
•   Browser bugs
•   No statistically significant results
•   Browser plugins and addons




       “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
•   Inaccurate millisecond timers
•   Browser bugs
•   No statistically significant results
•   Browser plugins and addons
•   No cross-browser testing


       “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
•   Inaccurate millisecond timers
•   Browser bugs
•   No statistically significant results
•   Browser plugins and addons
•   No cross-browser testing
•   Incorrect tests
       “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
•   Inaccurate millisecond timers
•   Browser bugs
•   No statistically significant results
•   Browser plugins and addons
•   No cross-browser testing
•   Incorrect tests
       “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Benchmarking pitfalls
•   Inaccurate millisecond timers
•   Browser bugs
•   No statistically significant results
•   Browser plugins and addons
•   No cross-browser testing
•   Incorrect tests
       “Bulletproof JavaScript benchmarks” — http://mths.be/asv
Unfair
comparisons
Function declarations
go in the preparation
code or in the setup.
Only the bare minimum
goes inside each test
body.
http://jsperf.com/string-reverse
http://jsperf.com/fibonacci-numbers
Make sure the methods
you’re comparing
actually do the same
thing.
If not, mention this in
the description of the
test case.
Make sure you’re testing
what you intended to
test.
http://jsperf.com/jquery-id-vs-
    native-getelementbyid
When re-using variables
across tests, make sure
you reset them as
needed.
http://jsperf.com/a-b-vs-a-a-b/2
Don’t introduce
randomness in your tests.
http://jsperf.com/zeropad
Don’t test asynchronous
stuff synchronously.
http://jsperf.com/settimeout-vs-setinterval/4
Asynchronous tests — a good example:

  http://jsperf.com/smallest-timeout
There’s a difference
between preparation, setup
and teardown.
Example: scope lookups

 http://jsperf.com/truth
Example: DOM cleanup

http://jsperf.com/basic-dom-manipulation
jsPerf uses Benchmark.js,
which allows for advanced
usage.
       http://benchmarkjs.com/docs
http://jsperf.com/removechild
This messes with your results, too:
This messes with your results, too:
• Unexpected browser features
This messes with your results, too:
• Unexpected browser features
• Dead code removal
This messes with your results, too:
• Unexpected browser features
• Dead code removal
•…
Questions?
 @mathias ~ @jsprf

More Related Content

Viewers also liked

It's a Deal... Reality News for The Week
It's a Deal... Reality News for The WeekIt's a Deal... Reality News for The Week
It's a Deal... Reality News for The Week
Itsadeal Coin
 
Personalmarketing 2.0 beitrag buckmann
Personalmarketing 2.0 beitrag buckmannPersonalmarketing 2.0 beitrag buckmann
Personalmarketing 2.0 beitrag buckmann
Jörg Buckmann
 
AAMP Track 4 Garden Room 2 PM
AAMP Track 4 Garden Room 2 PMAAMP Track 4 Garden Room 2 PM
AAMP Track 4 Garden Room 2 PM
Chris DeMartine
 
Awkward Family Photos Slide Show
Awkward Family Photos   Slide ShowAwkward Family Photos   Slide Show
Awkward Family Photos Slide Show
Andrew Isles
 
Hybrid Cars Presentation For History
Hybrid Cars Presentation For HistoryHybrid Cars Presentation For History
Hybrid Cars Presentation For History
MrG
 
Catalogue paname
Catalogue panameCatalogue paname
Catalogue paname
ksalivre
 

Viewers also liked (20)

Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
 
Uso de ipad como herramienta de Productividad Profesional
Uso de ipad como herramienta de Productividad ProfesionalUso de ipad como herramienta de Productividad Profesional
Uso de ipad como herramienta de Productividad Profesional
 
The web is the platform - why FirefoxOS matters
The web is the platform - why FirefoxOS mattersThe web is the platform - why FirefoxOS matters
The web is the platform - why FirefoxOS matters
 
Clara Campoamor Actividades Vaquema Educa
Clara Campoamor Actividades Vaquema EducaClara Campoamor Actividades Vaquema Educa
Clara Campoamor Actividades Vaquema Educa
 
Microsoft word rev. cient. art. cestería en f.d. 17 01 15
Microsoft word    rev. cient. art. cestería en f.d. 17 01 15Microsoft word    rev. cient. art. cestería en f.d. 17 01 15
Microsoft word rev. cient. art. cestería en f.d. 17 01 15
 
It's a Deal... Reality News for The Week
It's a Deal... Reality News for The WeekIt's a Deal... Reality News for The Week
It's a Deal... Reality News for The Week
 
Boletín XLIX diciembre 2014
Boletín XLIX diciembre 2014Boletín XLIX diciembre 2014
Boletín XLIX diciembre 2014
 
Personalmarketing 2.0 beitrag buckmann
Personalmarketing 2.0 beitrag buckmannPersonalmarketing 2.0 beitrag buckmann
Personalmarketing 2.0 beitrag buckmann
 
AAMP Track 4 Garden Room 2 PM
AAMP Track 4 Garden Room 2 PMAAMP Track 4 Garden Room 2 PM
AAMP Track 4 Garden Room 2 PM
 
Awkward Family Photos Slide Show
Awkward Family Photos   Slide ShowAwkward Family Photos   Slide Show
Awkward Family Photos Slide Show
 
SICUR 2016 - Appvision Presentation febrero 2016
SICUR 2016 - Appvision Presentation   febrero 2016SICUR 2016 - Appvision Presentation   febrero 2016
SICUR 2016 - Appvision Presentation febrero 2016
 
Socialpoint Audience Response Module
Socialpoint Audience Response ModuleSocialpoint Audience Response Module
Socialpoint Audience Response Module
 
Hybrid Cars Presentation For History
Hybrid Cars Presentation For HistoryHybrid Cars Presentation For History
Hybrid Cars Presentation For History
 
E-Mail-Verschlüsselung mit GnuPG
E-Mail-Verschlüsselung mit GnuPGE-Mail-Verschlüsselung mit GnuPG
E-Mail-Verschlüsselung mit GnuPG
 
RESTEK MAMS+ Audio Renderer Testbericht in HIFI STARS März 2015
RESTEK MAMS+ Audio Renderer Testbericht in HIFI STARS März 2015RESTEK MAMS+ Audio Renderer Testbericht in HIFI STARS März 2015
RESTEK MAMS+ Audio Renderer Testbericht in HIFI STARS März 2015
 
Google Hummingbird : ce que cela change pour le SEO - conférence SEO Campus 2014
Google Hummingbird : ce que cela change pour le SEO - conférence SEO Campus 2014Google Hummingbird : ce que cela change pour le SEO - conférence SEO Campus 2014
Google Hummingbird : ce que cela change pour le SEO - conférence SEO Campus 2014
 
Proyecto completo
Proyecto completoProyecto completo
Proyecto completo
 
Boas práticas técnica para um código limpo (Clean Code)
Boas práticas técnica para um código limpo (Clean Code)Boas práticas técnica para um código limpo (Clean Code)
Boas práticas técnica para um código limpo (Clean Code)
 
Bilmök 2017 - Microsoft Yeni Yesil Yazilim Geliştirme Teknolojileri
Bilmök 2017 - Microsoft Yeni Yesil Yazilim Geliştirme TeknolojileriBilmök 2017 - Microsoft Yeni Yesil Yazilim Geliştirme Teknolojileri
Bilmök 2017 - Microsoft Yeni Yesil Yazilim Geliştirme Teknolojileri
 
Catalogue paname
Catalogue panameCatalogue paname
Catalogue paname
 

Similar to Using jsPerf correctly

AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
colleenfry
 

Similar to Using jsPerf correctly (20)

Badneedles
BadneedlesBadneedles
Badneedles
 
The what, why and how of web analytics testing
The what, why and how of web analytics testingThe what, why and how of web analytics testing
The what, why and how of web analytics testing
 
Plugin Safety Check - How to Ensure Your Plugin Gets Approved
Plugin Safety Check - How to Ensure Your Plugin Gets ApprovedPlugin Safety Check - How to Ensure Your Plugin Gets Approved
Plugin Safety Check - How to Ensure Your Plugin Gets Approved
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
Hacker Proof web app using Functional tests
Hacker Proof web  app using Functional testsHacker Proof web  app using Functional tests
Hacker Proof web app using Functional tests
 
MidwestJS Zero to Testing
MidwestJS Zero to TestingMidwestJS Zero to Testing
MidwestJS Zero to Testing
 
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Static Code Analysis:  Keeping the Cost of Bug Fixing DownStatic Code Analysis:  Keeping the Cost of Bug Fixing Down
Static Code Analysis: Keeping the Cost of Bug Fixing Down
 
What is WAAT?
What is WAAT?What is WAAT?
What is WAAT?
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript Debugging
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
SSBSE 2020 keynote
SSBSE 2020 keynoteSSBSE 2020 keynote
SSBSE 2020 keynote
 
AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
AtlasCamp 2013: Show Me Number! Automated Browser Performance Testing
 
Static Analysis
Static AnalysisStatic Analysis
Static Analysis
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
How to Test PowerShell Code Using Pester
How to Test PowerShell Code Using PesterHow to Test PowerShell Code Using Pester
How to Test PowerShell Code Using Pester
 
Automation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 USAutomation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 US
 
Managing code quality with SonarQube - Radu Vunvulea
Managing code quality with SonarQube - Radu VunvuleaManaging code quality with SonarQube - Radu Vunvulea
Managing code quality with SonarQube - Radu Vunvulea
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
Performance Metrics for your Build Pipeline - presented at Vienna WebPerf Oct...
Performance Metrics for your Build Pipeline - presented at Vienna WebPerf Oct...Performance Metrics for your Build Pipeline - presented at Vienna WebPerf Oct...
Performance Metrics for your Build Pipeline - presented at Vienna WebPerf Oct...
 
Small is Beautiful- Fully Automate your Test Case Design
Small is Beautiful- Fully Automate your Test Case DesignSmall is Beautiful- Fully Automate your Test Case Design
Small is Beautiful- Fully Automate your Test Case Design
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Using jsPerf correctly