Skip to content

@malkia /gist:414091
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
/*
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
C:\> cl -O2 badif.c
C:\> badif
(i & 0x80000000) == 0 time: 0.674000
(i & 0xFFFFFFFF) == 0 time: 0.677000
(i & 0x00000001) == 0 time: 0.677000
(i & 0x00000003) == 0 time: 0.674000
(i & 0x00000002) == 0 time: 0.691000
(i & 0x00000008) == 0 time: 1.051000
(i & 0x00000010) == 0 time: 1.232000
Target: i686-pc-cygwin
gcc version 4.3.4 20090804 (release) 1 (GCC)
c:\>sh -c "gcc -O9 badif.c -o badif-gcc.exe"
c:\>badif-gcc
(i & 0x80000000) == 0 time: 0.000000
(i & 0xFFFFFFFF) == 0 time: 0.702000
(i & 0x00000001) == 0 time: 1.060000
(i & 0x00000003) == 0 time: 1.046000
(i & 0x00000002) == 0 time: 1.060000
(i & 0x00000008) == 0 time: 1.061000
(i & 0x00000010) == 0 time: 1.030000
*/
#include <time.h>
#include <stdio.h>
#define F(v) static int F##v() { int s=0,i; for(i=0; i<1073741824; i++) if(0==(i&v)) s++; return s; }
#define D(v) { #v, &F##v }
F(0x80000000)
F(0xFFFFFFFF)
F(0x00000001)
F(0x00000003)
F(0x00000002)
F(0x00000008)
F(0x00000010)
static struct { const char* name; int (*func) (); } f[]={
D(0x80000000),
D(0xFFFFFFFF),
D(0x00000001),
D(0x00000003),
D(0x00000002),
D(0x00000008),
D(0x00000010),
};
int timeit(int (*func)())
{
int x = clock();
func();
return clock() - x;
}
int main()
{
int i;
for( i=0; i<sizeof(f)/sizeof(f[0]); i++ )
{
printf( "(i & %s) == 0 time: %f\n", f[i].name, (double)timeit(f[i].func) / (double)CLOCKS_PER_SEC );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.