[erlang-questions] hrtime/0, Was: now/0 resolution
Alceste Scalas
alceste@REDACTED
Wed Sep 12 10:39:30 CEST 2007
Il giorno mer, 12/09/2007 alle 09.42 +0200, Raimo Niskanen ha scritto:
> Serge apparently want a new BIF e.g hrtime/0 that would return
> the best high resolution time the implementation knows on the
> running OS. The precision would be OS dependant, but the best
> known to the emulator, and it would be the fastest way to get it.
> This BIF could also be suitable for getting high resolution
> CPU time as well as wallclock time.
>
> How much interest for such a BIF is there from the community?
I would be interested in it.
> Came to think about it. The current suggestion for FFI
> (Forein Function Interface) could be used to call the OS
> high resolution time functions, but then you would have
> to know the right call on every OS, and I do not know
> how efficient that call interface would be.
It mostly depends on the number of function call arguments, because the
proposed FFI BIFs must perform type checking and conversion. Of course,
it would be possible to wrap the native clock function so it takes no
(or less) arguments.
But, as an example, the POSIX clock_gettime() writes its result in a
struct timespec, and one would need to write some accessor functions (in
C) in order to get its fields. Otherwise, the struct could be copied
(or written, if you're brave) into an Erlang binary, that in turn should
be matched into a couple of Erlang integers (for seconds and
microseconds).
If clock resolution and precision are needed, then I think it's
definitely too much work. A dedicated BIF would be required IMHO.
Regards,
alceste
--
Alceste Scalas <alceste@REDACTED>
CRS4 - http://www.crs4.it/
More information about the erlang-questions
mailing list