jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
$.fn.measureWidth = function() {
var span = jQuery._cacheSpan;
if (!span) {
var span = document.createElement('span');
span.style.whiteSpace = "nowrap";
span.style.margin = span.style.padding = 0;
jQuery._cacheSpan = span;
}
span.innerHTML = this.outerHTML;
return span.offsetWidth;
}
$.fn.measureWidthHide = function() {
var span = jQuery._cacheSpanHide;
if (!span) {
var span = document.createElement('span');
span.style.whiteSpace = "nowrap";
span.style.margin = span.style.padding = 0;
span.style.visibility = "hidden";
jQuery._cacheSpanHide = span;
}
span.innerHTML = this.outerHTML;
return span.offsetWidth;
}
$.fn.canvasMeasureWidth = function() {
if (!jQuery._cacheCanvas) {
var canvas = document.createElement('canvas');
var docFragment = document.createDocumentFragment();
docFragment.appendChild(canvas);
jQuery._cacheCanvas = canvas;
}
return jQuery._cacheCanvas.getContext("2d").measureText(text).width;;
}
var text = "YOU SHALL NOT PASS!";
Ready to run.
Test | Ops/sec | |
---|---|---|
Check width on not hidden |
| ready |
The same with hidden |
| ready |
Cached canvas |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.