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>
window.computeWidthDOM = function(text, font) {
var f = font || '12px arial';
var o = computeWidthDOM.o = computeWidthDOM.o || $('<span></span>')
.css({'visibility': 'hidden', 'font': f});
o.text(text);
o.appendTo($('body')),
w = o.innerWidth();
o.remove();
return w;
}
window.computeWidthCanvas = function(text, font) {
var f = font || '12px arial';
// re-use canvas object for better performance
var canvas = computeWidthCanvas.canvas || (computeWidthCanvas.canvas = document.createElement("canvas"));
var context = canvas.getContext("2d");
context.font = f;
var metrics = context.measureText(text);
return metrics.width;
};
window.textFont = "12pt Arial";
window.text = "YOU SHALL NOT PASS!";
Ready to run.
Test | Ops/sec | |
---|---|---|
DOM-based method |
| ready |
Canvas-based method |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.