/* adapted from the rand example from http://www.cplusplus.com/reference/cstdlib/rand/ */ #include /* generate */ #include /* accumulate */ #include /* vector for very long arrays */ #include /* printf, scanf, puts, NULL */ #include /* cout, endl */ #include /* srand, rand */ #include /* time */ int main() { std::vector li(20000000, 0); float res = 0; clock_t t1, t2; /* initialize random seed: */ srand (time(NULL)); std::generate(li.begin(), li.end(), std::rand); t1 = clock(); std::cout << std::accumulate(li.begin(), li.end(), 0) << std::endl; t2 = clock(); std::cout << (float(t2) - float(t1)) / CLOCKS_PER_SEC << std::endl; }