Closed Winand closed 6 years ago
Let's benchmark this:
<html>
<body>
<script>
var N = 1000000;
var t0;
function int1(x, base) {
if(base !== undefined) return parseInt(x, base);
return x<0 ? Math.ceil(x): Math.floor(x);
}
function int2(x, base) {
return parseInt(x, base);
}
t0 = performance.now();
for (var i=-N; i<N; i++) {
int1(i);
}
console.log(performance.now() - t0);
t0 = performance.now();
for (var i=-N; i<N; i++) {
int2(i);
}
console.log(performance.now() - t0);
</script>
</body>
</html>
On Chrome the results are more or less equal. On FF the first (as in current) implementation is much faster.
Thanks!
Can convert expressions with specified radix:
fixes #21
P. S.
int()
returns 0 in Python and NaN in pscript