Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

// runtime value dependent test.c

    #include <stdio.h>
    #include <malloc.h>
    #include <stdlib.h>
    int main(int argc, char **argv) {
        int element = 0;
        int iteration = 0;
        int iterations = 0;
        int innerloop = 0;
        double sum = 0.0;

        if (argc > 1)
            iterations = atoi(argv[1]);
        printf("iterations %d\n", iterations);
    
        int array_length = 1000000 * iterations;
        double *array = (double*)malloc(array_length * sizeof(double));    
    
        for (element = 0; element < array_length; element++)
            array[element] = element;
        for (iteration = 0; iteration < iterations; iteration++)
            for (innerloop = 0; innerloop < 1000000000; innerloop++)
                sum += array[(iteration + innerloop) % array_length];
        printf("sum %E\n", sum);
        free(array);
        array = NULL;
        return 0;
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: