Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to <a href="http://perldoc.perl.org/Time/HiRes.html#gettimeofday-%28%29" rel="nofollow">this documentation</a>, the <code>gettimeofday</code> function returns seconds or microseconds since the unix epoch, which is 1/1/1970 <strong>UTC</strong>. Because it is in UTC, it is not affected by time zones at all.</p> <p>Also, in your original code you are just using <code>gettimeofday</code>, which is going to be returning timestamps from <em>now</em>, not from 1970. But in your suggested answer, for some reason, you have hard-set the timestamp, which won't help you do much.</p> <p>Yes, there is history to just about every time zone, including Singapore. <a href="https://github.com/eggert/tz/blob/master/asia#L2416-2429" rel="nofollow">You can see it in the TZDB here</a>. But you are incorrect about it being +8:30 at the epoch. It was actually +7:30. <a href="http://www.timeanddate.com/worldclock/converted.html?iso=19700101T00&amp;p1=185&amp;p2=236" rel="nofollow">You can verify also on this site</a>. But it doesn't matter anyway because like I said, <code>gettimeofday</code> works strictly in UTC.</p> <p>I think the problem is in how you are interpreting the results. You have as your last line:</p> <pre><code>print STDOUT $time{'mm:ss.mmm', $stat_perf} . " \n"; </code></pre> <p>But <code>$stat_perf</code> is the elapsed duration of time, not a value that you can treat as a timestamp. You probably shouldn't be passing it to <code>$time</code>, since that <em>will</em> use the local time zone and be expecting a full timestamp.</p> <p>Also, you may want to use <code>tv_interval</code>, as shown <a href="http://perldoc.perl.org/Time/HiRes.html#EXAMPLES" rel="nofollow">in the examples</a>.</p> <h3>Update</h3> <p>I searched through the CPAN archives and I'm sure somewhere there is a module for formatting an elapsed duration of time, but I can't seem to find it. Anyway, it's not too hard to write this on your own. Here, this should work:</p> <pre><code>my $min = $stat_perf / 60; my $sec = ($stat_perf * 1000 % 60000) / 1000; my $elapsed = sprintf("%02u:%06.3f", $min, $sec); print STDOUT $elapsed . "\n"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload