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
When the location of a substring that should be replaced is known, what's faster: .replace or .substring?
<div id="bob">hi[br]bob</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
var bob_div = $("#bob"),
bob_div_text = $("#bob").text();
$.fn.text2 = function(text) {
this.text(text);
this.html(this.html().split('[br]').join('<br>'));
return this;
};
$.fn.text3 = function(text) {
this.text(text);
this.html(this.html().replace('[br]','<br>'));
return this;
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
substring |
| ready |
replace |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.