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
Try to figure out the best way to build strings in javascript.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js">
</script>
<script>
String.prototype.format = function() {
var args = arguments;
return this.replace(/\{(\d)\}/g, function(a, b) {
return typeof args[b] != 'undefined' ? args[b] : a;
});
}
String.prototype.formatReplace = function() {
var args = arguments,
i = args.length - 1;
var result = this;
while (i >= 0) {
result = result.replace('{' + i + '}', args[i]);
i--;
}
return result;
}
</script>
window.txt = "<ul><li>{0}</li><li>{1}</li><li>{2}</li></ul>";
window.t1 = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.";
window.t2 = "Aliquam tincidunt mauris eu risus.";
window.t3 = "Vestibulum auctor dapibus neque.";
window.ar1 = ["<ul><li>", "</li><li>", "</li><li>", "</li></ul>"];
window.ar2 = ["Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", "Aliquam tincidunt mauris eu risus.", "Vestibulum auctor dapibus neque."];
Ready to run.
Test | Ops/sec | |
---|---|---|
JS normal concat |
| ready |
JS replace function |
| ready |
jquery validate format function |
| ready |
String format function |
| ready |
Something else |
| ready |
Something else 2 |
| ready |
String format function using Replace |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.