Unless you have custom-compiled a near-realtime (or realtime) linux kernel,
timing anything less than a few seconds (in aggregate) is unlikely to give
you a meaningful result. Although, even if you have a RT kernel, the
hardware may not give accurate answers either (typically, it requires HPET
for microsecond accuracy, or more specialized features for better timing).

All that to say, the @time macro uses the system high performance clock,
and can return very small (although meaningless) numbers:

julia> @time ()
elapsed time: 1.171e-6 seconds (48 bytes allocated)

Therefore, for benchmarks, you should execute your code in a loop enough
times that the measurement error (of the hardware and OS) is not too
significant.


On Mon, Jun 2, 2014 at 12:39 AM, Iain Dunning <[email protected]> wrote:

> Not sure about the answer to your question, but on a side note, I'd
> recommend disabling the garbage collector if you want to get timings that
> accurate and you aren't able to average them out.
>
>
> On Monday, June 2, 2014 12:05:34 AM UTC-4, Joshua Job wrote:
>>
>> Hello all,
>>
>> I'm working on an optimization algorithm (based on some software written
>> in C), and will need to be able to get precise timing information for how
>> long it takes to find each solution. The optimizations will likely be very
>> fast (tens of microseconds perhaps) for some of my test problems.
>>
>> I'm not familiar with the accuracy of the @time macro. Does it accurately
>> time execution to within a microsecond? It will time functions as having
>> execution times of a few microseconds, but I don't know how accurate that
>> actually is.
>>
>> The C code this is based on uses clock_gettime to get timing information
>> accurate to a few nanoseconds. I don't quite need that accuracy, but the
>> unix system clock "time" accuracy of 10 milliseconds isn't acceptable.
>>
>> Also, running many times to get the time isn't an option as I am actually
>> interested in the distribution of times, as it is a heuristic algorithm. I
>> want to know how long would need to run it to have found a solution with,
>> say, 99% confidence, and so need the actual distribution of times to
>> solution.
>>
>> Thanks!
>>
>>

Reply via email to