I need to compare dates with the presicion of a second. In high school we probably would have done something like...
zzz... well I wrote a formula just to put everything in terms of seconds and then subtract.
I would have had to use doubles in school because our compilers only supported 16bit integers, but at home I can have 32bit or even 64bit integers (although to my understanding CPU's are not yet optimized for dealing with 64bit ints). Basically what I'm asking is there any mentionable performance difference what so ever between the if-else, int, or double method of solving this? Worst case this function would probably only be called about 100 in a row.
Thanks for any input
-blazko
code:<HR>Code:bool x_greaterthan_y(date x, date y) { if(x.year > y.year) return 1; else if(x.year < y.year return 0; else /*they're the same year */ if(x.month > y.month) return 1; //etc, etc, etc... }
zzz... well I wrote a formula just to put everything in terms of seconds and then subtract.
code:<HR>Code:bool x_greaterthan_y(date x, date y) { long int sx, sy; sx = x.year * 31536000 + x.day * 86400 + x.hour * 3600 + x.min * 60 + x.sec; sy = y.year * 31536000 + y.day * 86400 + y.hour * 3600 + y.min * 60 + y.sec; return ((sx - sy) > 0); }
I would have had to use doubles in school because our compilers only supported 16bit integers, but at home I can have 32bit or even 64bit integers (although to my understanding CPU's are not yet optimized for dealing with 64bit ints). Basically what I'm asking is there any mentionable performance difference what so ever between the if-else, int, or double method of solving this? Worst case this function would probably only be called about 100 in a row.
Thanks for any input
-blazko