Use C to traverse large numbers

Please help me write a simple C program that I can use to simply test the performance of JS, python and C.

js Code

-sharpinclude <stdio.h>
int x = 10000000000;
int n = 0;
int main() {
    for(int i = 0; i<x; iPP) n = n+i;
    printf("%d" ,n);
    printf("%s" ,": ok");
}
C cPP
Mar.24,2021

then replace the statements of x n and I with double

but the final result may deviate from the real result


1x 2m 3+. + 10000000000, the result of this formula is 5.0000000005Eq19, which is too large to be out of the range of int.
if you only measure the time of addition, it is recommended to use loop nesting, like this

for (int i = 0; i < 1000000; iPP) {
    n = 0;
    for (int j = 0; j < 10000; jPP) {
        n += j;
    }
}
Menu