|
|
|
|
|
by lucb1e
2588 days ago
|
|
I did some testing with pypy, which also works with arbitrarily large integers but iirc does JIT instead of interpretation (like cpython would do), so that should be similar to JS in V8 except that it has arbitrarily large integers. a = Math.pow(2, 1023)
t = new Date().getTime()
for (var i = 0; i < 1e7; i++) {
a += i;
}
console.log(new Date().getTime() - t);
vs a = pow(2, 1024)
t = time.time()
for i in range(int(1e7)):
a += i
print(time.time() - t)
Both ran a bunch of times: pypy does it in 279ms and nodejs in 250. I chose 1024 for Python because that is where JS starts to return infinity, so the JS code does operations on a number just below that. The time seems to be spent in the loop, as an empty loop or a loop doing a+=0 is 20x faster.Lowering the exponent to 100, JS spends 269ms and pypy 142. Not sure why that is, but having arbitrarily large integers doens't seem to make this arithmetic any faster. I don't know how to quickly toy around with fraction-based floats, but at least for arbitrarily large integers, I'm not sure why we're going to have to put up with new syntax. |
|
I tried in C:
and timed it. The time taken was 17ms.