lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Nov 13, 2009 at 1:11 PM, Ico <lua@zevv.nl> wrote:
>
>
> * On 2009-11-13 steve donovan <steve.j.donovan@gmail.com> wrote  :
>
>> On Fri, Nov 13, 2009 at 3:02 PM, Andreas Krinke <andreas.krinke@gmx.de> wrote:
>> > os.clock() uses clock() from time.h which returns used processor time,
>> > not time since Lua started.
>>
>> D:\downloads>lua -e "print(os.clock())"
>> 0
>
> Your program just used 0 seconds of processor time.
>
>  ico@lapdoos:~$ lua -e "a=1; for i = 1, 1000000 do a=a+1 end; print(os.clock())"
>  0.09
>
> This process was using the CPU for 0.09 seconds
>
>  ico@lapdoos:~$ lua -e "os.execute('sleep 1'); print(os.clock())"
>  0
>
> And this one, although running for 1 second, used 0 seconds of CPU time
> as well. The os.execute() call blocks until the child process finishes,
> and blocking system calls do not use the CPU.

This is precisely why I use socket.gettime().  It gives you a number
with ms precision that you can then compare to determine how much real
time has passed.

- Jim