04/16/2009 05:39PM | Stewart Gateley
This is exactly what the ColdFusion built-in function GetTickCount() is for.
Also, you are way off on your measurements of how fast each method is. You can't measure the whole page load time as there are many factors there to skew your results.
I ran several tests using GetTickCount(), CreateObject('java','java.util.Date').getTime() and DateDiff('s', CreateDate(1970,1,1), Now()) with a timer wrapped around each of them, in almost all cases every method executed in sub 1 ms and never above 1 ms for any call. The times that I did see 1ms was most likely my internal counter passing to the next ms during execution, thus I believe all calls are just as efficient, however GetTickCount() is much shorter and easier to use.
Test code:
#GetTickCount()# - #GetTickCount() - now# ms
#CreateObject('java','java.util.Date').getTime()# - #GetTickCount() - now# ms
#DateDiff('m', CreateDate(1970,1,1), Now())# - #GetTickCount() - now# ms
Note: The last method only returns the number of seconds, not the number of milliseconds like the prior two.