[luau] getting system time in milisecs

Ray Strode halfline at hawaii.rr.com
Wed Sep 18 19:30:00 PDT 2002


>
>
>I have some code that loops with some real-time constraints, and I need to
>check the time per cycle. 
>
Do you really need to check it per iteration?  I mean, in your case, 
could you move the timing outside
the loop and divide the result by the number of iterations?  If you do 
that, then you will get an average
iteration which will minimize the time spent timing.

>The problem I run into is that adding "debug" to log the time is somewhat
>
>inaccurate and impacts the loop. 
>
Not quite sure what you mean by "debug".  You mean the timing code is 
skewing your results?
Here's an idea:  say get_time() is your timing function (be it from 
gettimeofday() or clock() or whatever),
before you start your loop do a little profiling of the timing function, 
something like

before = get_time();
for (i = 0, total = 0; i < 10000; i++) {
get_time();
}
timing_cost = (get_time() - before) / 10000

Then you have a rough idea of what get_time() is going to take during 
your loop, so you can
subtract it out from the results.

On a side note, there is a syscall called times() which fills a 
structure that contains clock ticks since the
start of the  program.  It has two fields. One of the fields is the 
clock ticks spent in kernel-space and the other is
the clock ticks spent in userspace.  If you might be able to use it to 
isolate the times from parts of you program,
too.

--Ray





More information about the LUAU mailing list