Trying write a basic benchmarking code but its not working

I am testing ceil vs floor and somehow calling floor 67108864 times results in zero ticks. I know that isn't right, any help/understanding is appreciated.
Here is the output.

ceil test
1297 Clock ticks
1.2970 Seconds
Loops 67108864

floor test
0 Clock ticks
0.0000 Seconds
Loops 67108864



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
35
36
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
using namespace std;


int main(void)
{
	float a=5.813f,test;
	clock_t start,end;
	unsigned long i;

	start=clock();
	for(i=0;i<1024*1024*64;++i)
	{
		test=ceil(a);
	}
	end=clock();
	cout<<"ceil test"<<endl;
	printf("%.0f Clock ticks\n%.4f Seconds\nLoops %li\n",(float)end-start,(float)(end-start)/CLK_TCK,1024*1024*64);

	start=clock();
	for(i=0;i<1024*1024*64;++i)
	{
		test=floor(a);
	}
	end=clock();
	cout<<"floor test"<<endl;
	printf("%.0f Clock ticks\n%.4f Seconds\nLoops %li\n",(float)end-start,(float)(end-start)/CLK_TCK,1024*1024*64);

	char z;
	cin >> z;

	return 0;
}

Last edited on
It works fine for me...
Look for some compiler optimization that allows compiler to reorder instructions. Then disable that one. ;-)

And you should use double with floor() or else you are not only testing floor, but also your friendly compiler's float->double->float conversion speed.

Ciao, Imi.
And you should use double with floor() or else you are not only testing floor, but also your friendly compiler's float->double->float conversion speed.

Waitasecond.. that was wrong. floor has a float version too.. Confused it with sin() and sinf ("floorf" would sound somehow.. offending. ;-)

Ciao, Imi.
I couldn't find any optimization remotely close to reorder instructions (using vs2008).

This is what is on:
Optimization: Maximize speed (/O2)
Enable Intrinsic Functions: Yes (/Oi)
Whole Program Optimization: Enable link-time code generation (/GL)
Topic archived. No new replies allowed.