StringEngine charAt
JavaScript performance comparison
Preparation code
<script type="text/javascript">
var FROMHTMLCODE = {
"&": "\u0026"
},
FROMHTMLNAME = {
"&": "\u0026"
},
X = /\&[\w]+\;|\&\#[\d]+\;|\&+/;
function charAtA(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
if ((m = x.exec(s)) === null) {
return s ;
} else if ((v = m.shift()).length === 1) {
return v ;
}
return (typeof (c = FROMHTMLNAME[v]) === "string") ? c : (typeof (c = FROMHTMLCODE[v]) === "string") ? c : s ;
}
}
return null ;
}
function charAtB(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
return ((m = x.exec(s)) === null) ? s : ((v = m.shift()).length === 1) ? v : (typeof (c = FROMHTMLNAME[v]) === "string") ? c : (typeof (c = FROMHTMLCODE[v]) === "string") ? c : s ;
}
}
return null ;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
charAt A |
|
pending… |
charAt B |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Jonathan Perry
- Revision 2: published by Jonathan Perry
- Revision 3: published by Jonathan Perry
- Revision 4: published by Jonathan Perry
- Revision 5: published by Jonathan Perry
- Revision 6: published by Jonathan Perry
- Revision 7: published by Jonathan Perry
- Revision 8: published by Jonathan Perry
- Revision 9: published by Jonathan Perry
0 comments