|
|
|
|
|
by umanwizard
2588 days ago
|
|
25 nanoseconds is much longer than a normal double-precision addition, loop counter increment, and conditional jump back to the top of a loop should take, so there's something other than the time taken by additions that's going on in your benchmark. I'm not a Node.JS expert, but I suspect it's not getting JITted properly, or getting poorly optimized if so. I tried in C: #include <math.h>
#include <stdio.h>
int main()
{
double a = pow(2, 100);
for (double i = 0; i < 1e7; ++i) {
a += i;
}
printf("%f\n", a);
}
and timed it. The time taken was 17ms. |
|