tok
JavaScript performance comparison
Info
similar to PHP strtok()
Preparation code
<script>
Benchmark.prototype.setup = function() {
function tokA ( s, chars, rtl ) {
var i = chars.length;
rtl = true === rtl ? 'pop' : 'shift';
while ( i-- ) {
s = s.split(chars[i])[rtl]();
}
return s;
}
function tokB ( s, chars, rtl ) {
var n, i = chars.length;
rtl = true === rtl;
while ( i-- ) {
n = s.indexOf(chars[i]);
s = n < 0 ? s : rtl
? s.substr(++n)
: s.substr(0, n);
}
return s;
}
function tokC ( s, chars, rtl ) {
var n, i = chars.length;
rtl = true === rtl;
while ( i-- ) {
n = s.indexOf(chars[i]);
s = n < 0 ? s : rtl
? s.slice(++n)
: s.slice(0, n);
}
return s;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
tokA |
|
pending… |
tokB |
|
pending… |
tokC |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments