D Paste by downs
Description: mandelbrot bench
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import std.stdio, std.c.time, std.string; const int ITER=50; const float LIMIT_SQUARE=4.0; extern(C) { struct timeval { uint tv_sec; int tv_usec; } int gettimeofday(timeval *tv, void *tz); } void main(string[] args) { timeval start, end; foreach (arg; args[1..$]) { int size=arg.atoi(); gettimeofday(&start, null); int count=0; auto fac=2.0/size; for (double y=0; y<size; ++y) { for (double x=0; x<size; ++x) { cdouble C=(x*fac - 1.5) + (y*fac - 1.0)*1.0i, Z=C; int i = ITER; do Z=Z*Z+C; while (!(Z.im + Z.re > LIMIT_SQUARE) && --i > 0); if (!i) ++count; } } gettimeofday(&end, null); auto t1 = start.tv_sec*1000.0 + start.tv_usec/1000.0; auto t2 = end.tv_sec*1000.0 + end.tv_usec/1000.0; writefln("duration ", t2-t1, " count ", count); } } |