StringEngine charAt
JavaScript performance comparison
Preparation code
<script type="text/javascript">
var FROMHTMLCODE = {
"&": "\u0026"
},
FROMHTMLNAME = {
"&": "\u0026"
},
X = /\u0026[\w]+\u003b|\u0026\u0023[\d]+\u003b|\u0026+/,
A = "\u0026";
function charAtA(i, s) {
var x = X, a = A, m, v, c;
if (typeof i === "number") {
x.lastIndex = i;
if (typeof s === "string") {
return ((v = s.charAt(i)) === a) ? ((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 : v ;
}
}
return null ;
}
function charAtB(i, s) {
var v, x, a, m, c;
if (typeof i === "number" && typeof s === "string") {
v = s.charAt(i);
a = A;
if (v === a) {
x = X;
x.lastIndex = i;
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 ;
} else {
return v;
}
}
return null ;
}
function charAtC(i, s) {
var v, x, a, m, c;
if (typeof i === "number" && typeof s === "string") {
v = s.charAt(i);
a = A;
if (v === a) {
x = X;
x.lastIndex = i;
m = x.exec(s);
if (m === null) {
return s ;
} else {
v = m.shift();
if (v.length === 1) {
return v ;
} else {
return (typeof (c = FROMHTMLNAME[v]) === "string") ? c : (typeof (c = FROMHTMLCODE[v]) === "string") ? c : s ;
}
}
} else {
return v;
}
}
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… |
charAt C |
|
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