On recent (&gt;2009) Linux, you can call clock_gettime() with CLOCK_REALTIME_COARSE which is about 6x faster:<div><br></div><div><a href="https://gist.github.com/3634708">https://gist.github.com/3634708</a></div><div><br></div>
<div>On my workstation calling clock_gettime(CLOCK_REALTIME, ...) and poking the value into a Haskell struct takes about 70ns, with CLOCK_REALTIME_COARSE it&#39;s about 19ns (with a much lower stddev). Worth using for this application if it&#39;s available. Of course, in Snap we do the &quot;update the clock every second in a thread&quot; trick also.</div>
<div><br>G<br><br><div class="gmail_quote">On Wed, Sep 5, 2012 at 4:10 AM, Kazu Yamamoto <span dir="ltr">&lt;<a href="mailto:kazu@iij.ad.jp" target="_blank">kazu@iij.ad.jp</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Bryan,<br>
<div class="im"><br>
&gt;&gt; To my experience, the assumption 2) is not right. getttimeofday()<br>
&gt;&gt; is implemented in user land in Linux 3 but it is a system call<br>
&gt;&gt; in Linux 2.<br>
&gt;<br>
&gt; Just a nit: your history here is not correct. gettimeofday has been<br>
&gt; implemented as a vsyscall for a long time, maybe 5 years. And while it&#39;s<br>
&gt; faster than int 0x80, it&#39;s not that much faster: 2x or so on modern hardware.<br>
<br>
</div>Thank you for your correction.<br>
<br>
To whose who are interested in, additional information can be found<br>
from:<br>
<br>
        <a href="http://en.chys.info/2009/01/linux%E2%80%99s-vsyscall/" target="_blank">http://en.chys.info/2009/01/linux%E2%80%99s-vsyscall/</a><br>
<br>
Anyway, I believe we should avoid gettimeofday as much as possible<br>
to implement fast servers.<br>
<div class="HOEnZb"><div class="h5"><br>
--Kazu<br>
<br>
_______________________________________________<br>
web-devel mailing list<br>
<a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Gregory Collins &lt;<a href="mailto:greg@gregorycollins.net" target="_blank">greg@gregorycollins.net</a>&gt;<br>
</div>