#ifdef _WIN32
#include <windows.h>
#else
#define __int64 long long
#include <sys/time.h>
#include <stdlib.h>
#endif
//
// cl /O2 fract.cpp
//
#include <stdio.h>
void tstart(void);
void tend(void);
double tval(void);
int main(int ac, char *av[])
{
double a,b,c,d;
double x,y,x1,y1;
unsigned long iterations;
unsigned long starttime, endtime;
double tim;
iterations = 100000000;
if(ac != 5) {
a = .1;
b = .1;
c = .1;
d = .1;
}
else {
a = atof(av[1]);
b = atof(av[2]);
c = atof(av[3]);
d = atof(av[4]);
if(ac > 5)
iterations = atoi(av[5]);
}
unsigned long i;
//
// x1 = x0*x0 + c
//
// where x0 and c are complex numbers.
// x0 = a + bi;
// c = c + di;
//
tstart();
x = a;
y = b;
for(i = 0; i < iterations; i++) {
x1 = x*x - y*y;
y1 = -2 * x * y;
if( (x1*x1 + y1*y1) > 1.0)
break;
x = x1 + c;
y = y1 + d;
}
tend();
tim = tval();
printf("fract %13.9f %13.9f %13.9f %13.9f iter=%u time %8.3f seconds\n",
a,b,c,d,i,tim);
return 0;
}
#ifdef _WIN32
static LARGE_INTEGER _tstart, _tend;
static LARGE_INTEGER freq;
void tstart(void)
{
static int first = 1;
if(first) {
QueryPerformanceFrequency(&freq);
first = 0;
}
QueryPerformanceCounter(&_tstart);
}
void tend(void)
{
QueryPerformanceCounter(&_tend);
}
double tval()
{
return ((double)_tend.QuadPart -
(double)_tstart.QuadPart)/((double)freq.QuadPart);
}
#else
static struct timeval _tstart, _tend;
static struct timezone tz;
void tstart(void)
{
gettimeofday(&_tstart, &tz);
}
void tend(void)
{
gettimeofday(&_tend,&tz);
}
double tval()
{
double t1, t2;
t1 = (double)_tstart.tv_sec + (double)_tstart.tv_usec/(1000*1000);
t2 = (double)_tend.tv_sec + (double)_tend.tv_usec/(1000*1000);
return t2-t1;
}
#endif
|