Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using jsPerf correctly

41,688 views

Published on

These slides are probably not gonna make much sense without hearing my explanations, but oh well :)

Published in: Technology

Using jsPerf correctly

  1. Using jsPerf correctly@mathias – #jsconfeu 2011
  2. <sup>
  3. @mathias
  4. jsPerf
  5. jsPerf is 426 days old.24,164 test cases → ~56.72 per day83,536 tests → ~3.46 per test case1,012 comments → ~2.38 per day
  6. jsPerf is 426 days old.24,164 test cases → ~56.72 per day83,536 tests → ~3.46 per test case1,012 comments → ~2.38 per day
  7. “68% of all jsPerf test cases is broken.” — Jean-Jacques Rousseau
  8. “It would be unwise to takeall jsPerf results for granted.” — William Shakespeare
  9. Benchmarking pitfalls “Bulletproof JavaScript benchmarks” — http://mths.be/asv
  10. Benchmarking pitfalls• Inaccurate millisecond timers “Bulletproof JavaScript benchmarks” — http://mths.be/asv
  11. Benchmarking pitfalls• Inaccurate millisecond timers• Browser bugs “Bulletproof JavaScript benchmarks” — http://mths.be/asv
  12. Benchmarking pitfalls• Inaccurate millisecond timers• Browser bugs• No statistically significant results “Bulletproof JavaScript benchmarks” — http://mths.be/asv
  13. Benchmarking pitfalls• Inaccurate millisecond timers• Browser bugs• No statistically significant results• Browser plugins and addons “Bulletproof JavaScript benchmarks” — http://mths.be/asv
  14. 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
  15. 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
  16. 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
  17. 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
  18. Unfaircomparisons
  19. Function declarationsgo in the preparationcode or in the setup.
  20. Only the bare minimumgoes inside each testbody.
  21. http://jsperf.com/string-reverse
  22. http://jsperf.com/fibonacci-numbers
  23. Make sure the methodsyou’re comparingactually do the samething.
  24. If not, mention this inthe description of thetest case.
  25. Make sure you’re testingwhat you intended totest.
  26. http://jsperf.com/jquery-id-vs- native-getelementbyid
  27. When re-using variablesacross tests, make sureyou reset them asneeded.
  28. http://jsperf.com/a-b-vs-a-a-b/2
  29. Don’t introducerandomness in your tests.
  30. http://jsperf.com/zeropad
  31. Don’t test asynchronousstuff synchronously.
  32. http://jsperf.com/settimeout-vs-setinterval/4
  33. Asynchronous tests — a good example: http://jsperf.com/smallest-timeout
  34. There’s a differencebetween preparation, setupand teardown.
  35. Example: scope lookups http://jsperf.com/truth
  36. Example: DOM cleanuphttp://jsperf.com/basic-dom-manipulation
  37. jsPerf uses Benchmark.js,which allows for advancedusage. http://benchmarkjs.com/docs
  38. http://jsperf.com/removechild
  39. This messes with your results, too:
  40. This messes with your results, too:• Unexpected browser features
  41. This messes with your results, too:• Unexpected browser features• Dead code removal
  42. This messes with your results, too:• Unexpected browser features• Dead code removal•…
  43. Questions? @mathias ~ @jsprf

×