<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 25, 2016 at 8:51 AM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Thu, Mar 24, 2016 at 10:05:17PM -0700, Eliot Miranda wrote:<br>
&gt;<br>
&gt;<br>
&gt; &gt; On Mar 23, 2016, at 6:55 PM, David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt;&gt; On Wed, Mar 23, 2016 at 05:50:19PM -0700, Eliot Miranda wrote:<br>
&gt; &gt;&gt;&gt; On Wed, Mar 23, 2016 at 4:51 PM, David T. Lewis &lt;<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>&gt; wrote:<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; On Wed, Mar 23, 2016 at 04:22:21PM -0700, Eliot Miranda wrote:<br>
&gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt;&gt; Turns out this isn&#39;t needed for Cog.  I have ioLocalSecondsOffset which<br>
&gt; &gt;&gt;&gt;&gt; answers a value determined at start-up and only changed<br>
&gt; &gt;&gt;&gt;&gt; via ioUpdateVMTimezone, which itself is controlled by<br>
&gt; &gt;&gt;&gt;&gt; primitiveUpdateTimezone, #243.  So ioUTCMicroseconds is all that&#39;s needed<br>
&gt; &gt;&gt;&gt;&gt; to get at the clock and timezone atomically.<br>
&gt; &gt;&gt;&gt;<br>
&gt; &gt;&gt;&gt; If it is updated at start-up, then it&#39;s wrong. Think of daylight savings<br>
&gt; &gt;&gt;&gt; time transitions.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; So update it automatically once a second or some such?<br>
&gt; &gt;<br>
&gt; &gt; Are you joking, or is that a serious question?<br>
&gt;<br>
&gt; Yes.  I see two or three system calls in the code below.  gettimeofday, one inside localtime and one inside gmtime.  That&#39;s expensive.<br>
&gt;<br>
<br>
</span>It&#39;s gettimeofday() and localtime(). The #else is fallback for older unix platforms.<br></blockquote><div><br></div><div>As I said, two or three.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">In any case, caching the value and updating it periodically does not sound like a good idea to me.<br></blockquote><div><br></div><div>Why not?  Why does the time zone need to be determined on every time call even though it only has a resolution of seconds?  If including the timezone in every time call slows down accessing the time by, say, 33%, is it a good idea, when the VM can easily eliminate this overhead?</div><div><br></div><div><div>| c |</div><div>c := LargePositiveInteger.</div><div>[1 to: 10000000 do: [:i| c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8. c basicNew: 8]] timeToRun 884</div><div><br></div><div><br></div><div><br></div><div>[1 to: 10000000 do: [:i| Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock. Time utcMicrosecondClock]] timeToRun 6412</div><div><br></div><div><br></div><div>6412 / 884.0 7.253393665158371</div></div><div><br></div><div>So the overhead of the system calls involved in accessing time are much greater than the costs of allocating and garbage collecting 64-bit large integer results; much larger.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Dave<br>
<div class=""><div class="h5"><br>
<br>
&gt; &gt;<br>
&gt; &gt; Confused,<br>
&gt; &gt; Dave<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; /* implementation of ioUtcWithOffset(), defined in config.h to<br>
&gt; &gt; /* override default definition in src/vm/interp.h<br>
&gt; &gt; */<br>
&gt; &gt; sqInt sqUnixUtcWithOffset(sqLong *microSeconds, int *offset)<br>
&gt; &gt; {<br>
&gt; &gt;  struct timeval timeval;<br></div></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">
&gt; &gt;  if (gettimeofday(&amp;timeval, NULL) == -1) return -1;<br>
&gt; &gt;  time_t seconds= timeval.tv_sec;<br>
&gt; &gt;  suseconds_t usec= timeval.tv_usec;<br>
&gt; &gt;  *microSeconds= seconds * 1000000 + usec;<br>
&gt; &gt; #if defined(HAVE_TM_GMTOFF)<br>
&gt; &gt;  *offset= localtime(&amp;seconds)-&gt;tm_gmtoff;<br>
&gt; &gt; #else<br>
&gt; &gt;  {<br>
&gt; &gt;    struct tm *local= localtime(&amp;seconds);<br>
&gt; &gt;    struct tm *gmt= gmtime(&amp;seconds);<br>
&gt; &gt;    int d= local-&gt;tm_yday - gmt-&gt;tm_yday;<br>
&gt; &gt;    int h= ((d &lt; -1 ? 24 : 1 &lt; d ? -24 : d * 24) + local-&gt;tm_hour - gmt-&gt;tm_hour);<br>
&gt; &gt;    int m= h * 60 + local-&gt;tm_min - gmt-&gt;tm_min;<br>
&gt; &gt;    *offset= m * 60;<br>
&gt; &gt;  }<br>
&gt; &gt; #endif<br>
&gt; &gt;  return 0;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>