// doublespeed.cpp
#include <stdio.h>
#include <time.h>
inline void floatrun(void)
{
float m=0.0f;
float n=0.0f;
long t1=0;
long t2=0;
long i=0;
printf("Counting 1.4 billion floats...\n");
t1=clock();
while(m<1000.0f)
{
n=0.0f;
while(n<1000.0f)
{
n+=0.01f;
i++;
}
m+=0.01f;
}
t2=clock();
printf("Done. i=%ld, n=%f, time=%fs.\n",i,n,
(double)(t2-t1)/CLOCKS_PER_SEC);
}
inline void doublerun(void)
{
double m=0.0;
double n=0.0;
long t1=0;
long t2=0;
long i=0;
printf("Counting 1.4 billion doubles...\n");
t1=clock();
while(m<1000.0)
{
n=0.0;
while(n<1000.0)
{
n+=0.01;
i++;
}
m+=0.01;
}
t2=clock();
printf("Done. i=%ld, n=%f, time=%fs.\n",i,n,
(double)(t2-t1)/CLOCKS_PER_SEC);
}
int main(int argc, char** argv)
{
floatrun();
doublerun();
floatrun();
doublerun();
return 0;
}