Rate counter: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Ring}}: Remove vanity tags) |
|||
Line 1,136: | Line 1,136: | ||
Rate: 14211.98 per second</pre> |
Rate: 14211.98 per second</pre> |
||
The <tt>Instant</tt> type in Perl 6 is defined to be based on TAI seconds, and represented with rational numbers that are more than sufficiently accurate to represent your clock's accuracy. The actual accuracy will depend on your clock's accuracy (even if you don't have an atomic clock in your kitchen, your smartphone can track various orbiting atomic clocks, right?) modulo the vagaries of returning the atomic time (or unreasonable facsimile) via system calls and library APIs. |
The <tt>Instant</tt> type in Perl 6 is defined to be based on TAI seconds, and represented with rational numbers that are more than sufficiently accurate to represent your clock's accuracy. The actual accuracy will depend on your clock's accuracy (even if you don't have an atomic clock in your kitchen, your smartphone can track various orbiting atomic clocks, right?) modulo the vagaries of returning the atomic time (or unreasonable facsimile) via system calls and library APIs. |
||
=={{header|Phix}}== |
|||
On windows, time() advances in ~0.015s increments, whereas on linux it is ~0.0000016s. |
|||
<lang Phix>procedure task_to_measure() |
|||
sleep(0.1) |
|||
end procedure |
|||
printf(1,"method 1: calculate reciprocal of elapsed time:\n") |
|||
for trial=1 to 3 do |
|||
atom t=time() |
|||
task_to_measure() |
|||
t = time()-t |
|||
string r = iff(t?sprintf("%g",1/t):"inf") |
|||
printf(1,"rate = %s per second\n",{r}) |
|||
end for |
|||
printf(1,"method 2: count completed tasks in one second:\n") |
|||
for trial=1 to 3 do |
|||
integer runs=0 |
|||
atom finish=time()+1 |
|||
while true do |
|||
task_to_measure() |
|||
if time()>=finish then exit end if |
|||
runs += 1 |
|||
end while |
|||
printf(1,"rate = %d per second\n",runs) |
|||
end for</lang> |
|||
{{out}} |
|||
Of course it fails to achieve the perfect 10/s, due to the overhead of call/ret/time/printf etc. |
|||
<pre> |
|||
method 1: calculate reciprocal of elapsed time: |
|||
rate = 9.17431 per second |
|||
rate = 9.09091 per second |
|||
rate = 9.17431 per second |
|||
method 2: count completed tasks in one second: |
|||
rate = 9 per second |
|||
rate = 9 per second |
|||
rate = 9 per second |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |