Test name | Executions per second |
---|---|
isNaN | 0.7 Ops/sec |
regex | 0.7 Ops/sec |
window.case1 = new Proxy({}, {
get(t, p, r) {
if (typeof p === 'string' && !isNaN(p)) {
return +p
}
else {
return Reflect.get(t, p, r)
}
}
});
window.case2 = new Proxy({}, {
get(t, p, r) {
if (/^\d+$/.test(p)) {
return +p
}
else {
return Reflect.get(t, p, r)
}
}
});
window.gabage1 = 0;
window.gabage2 = 0;
for (let i = 0; i < 1e6;i++) { gabage1 =+ case1[i]; }
for (let i = 0; i < 1e6;i++) { gabage2 += case2[i]; }