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>
function regex(num) {
return num.toString().replace(/[13579](?=[13579])/g, "$&-");
}
function forloop(num) {
num = num.toString()
newstring = ''
for ( i = 0; i < num.length; i++ ){
if(num[i] % 2 !== 0 && num[i+1] % 2 !== 0){
newstring += num[i] + '-'
} else {
newstring += num[i]
}
}
if (newstring[newstring.length - 1] === '-'){
return newstring.slice(0, -1)
}
return newstring
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
regex |
| ready |
forloop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.