All pastes #483064 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-11 15:29 UTC
rendered paste body
cat macroSwapc.c
#include <stdio.h>
#include <time.h>
#define swap(x,y) double temp=x;x=y;y=temp
#define MAX 10000000
main()
{
int x;
int y;
int i;
double d1=1.535,d2=2.565;
clock_t c0,c1;
x=5;y=1;
printf("before swap x is %d %d",x,y);
c0=clock();
for (i=0;i<MAX;i++)
{
swap(x,y);
}
c1=clock();
printf("after swap x,y is %d %d",x,y);
printf("Swap time(integers): %.2lf\n",(double)(c1-c0)/CLOCKS_PER_SEC);
c0=clock();
for (i=0;i<MAX;i++)
{
swap(d1,d2);
}
c1=clock();
printf("Swap time(doubles): %.2lf\n", (double)(c1-c0)/CLOCKS_PER_SEC);

}