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, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
if ((v = s.charAt(i)) === A) {
if ((m = x.exec(s)) === null) {
return s ;
} else {
if ((v = m.shift()).length === 1) {
return v ;
} else {
return (typeof (c = FROMHTMLNAME[v]) === "string") ? c : (typeof (c = FROMHTMLCODE[v]) === "string") ? c : s ;
}
}
} else {
return v ;
}
}
}
return null ;
}
function charAtB(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = 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 charAtC(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
if ((v = s.charAt(i)) === A) {
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 charAtD(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
if ((v = s.charAt(i)) === A) {
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 v ;
}
}
return null ;
}
function charAtE(i, s) {
var x, m, v, c;
if (typeof i === "number") {
(x = X).lastIndex = i;
if (typeof s === "string") {
v = s.charAt(i);
if (v === A) {
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 charAtF(i, s) {
var v, a = A, x = X, m, c;
if (typeof i === "number" && typeof s === "string") {
v = s.charAt(i);
if (v === a) {
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 ;
}
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… |
charAt D |
|
pending… |
charAt E |
|
pending… |
charAt F |
|
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