#include <cstdlib> // for drand48()
#include <cstdio> // for printf()
#include <sys/time.h> // for gettimeofday()
// note: we probably don't want gettimeofday() but keeping the concepts simple
// for now, cf https://[Log in to view URL]
int main()
{
struct timeval start, stop;
gettimeofday(&start,nullptr);
double d[1000000];
for(int i=0; i<1000000; i++)
d[i]=drand48();
gettimeofday(&stop,nullptr);
auto elapsed = (stop.tv_sec * 1000000LL + stop.tv_usec)
- (start.tv_sec * 1000000LL + start.tv_usec);
printf("operation took %g seconds\n",elapsed/1000000.0);
printf("%g %g %g\n",d[0], d[1], d[2]);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: