lua-users home
lua-l archive

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


os.clock() returns the amount of CPU time used by your program.  If you're interested in wallclock time, perhaps os.time() is what you're looking for.  That won't get you fractional seconds,  however.  I wouldn't think that being suspended waiting for I/O to complete would cause CPU time to be accumulated but perhaps something weird is going on in the Windoze port.


On Sep 23, 2008, at 10:22 PM, Linker wrote:

May luasocket's gettime function will help you.

> require'socket'
> =socket.gettime()
1222222809.1984
>

luasocket 2.0.2

On Tue, Sep 23, 2008 at 8:16 PM, Shmuel Zeigerman <shmuz@013net.net> wrote:
I have an interactive Lua script that prompts user with a question and waits for an answer string from the standard input. The script measures the time it takes user to enter the answer, and the measurement should have 100 ms accuracy (or better).

Under Windows, it's achieved trivially by calling os.clock twice and subtracting the first value from the second. However, under Linux, the function returns 0 both times.

The questions:

1. How can I get time intervals of waiting for keyboard input measured with the 100 ms accuracy under Linux?

2. Is there a Lua solution to this problem that is portable between (at least) Linux and Windows?

Thanks.
--
Shmuel



--
Regards,
Linker M Lin
linker.m.lin@gmail.com