Rate counter: Difference between revisions
Content added Content deleted
(→{{header|Raku}}: raku got faster in ten years, so bump difficulty) |
|||
Line 1,866: | Line 1,866: | ||
sub factorial($n) { (state @)[$n] //= $n < 2 ?? 1 !! $n * factorial($n-1) } |
sub factorial($n) { (state @)[$n] //= $n < 2 ?? 1 !! $n * factorial($n-1) } |
||
runrate |
runrate 100_000, { state $n = 1; factorial($n++) } |
||
runrate |
runrate 100_000, { state $n = 1; factorial($n++) }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Start time: |
<pre>Start time: 2023-04-19T08:23:50.276418Z |
||
End time: |
End time: 2023-04-19T08:23:54.716864Z |
||
Elapsed time: |
Elapsed time: 4.440445313 seconds |
||
Rate: |
Rate: 22520.26 per second |
||
Start time: |
Start time: 2023-04-19T08:23:54.726913Z |
||
End time: |
End time: 2023-04-19T08:23:54.798238Z |
||
Elapsed time: 0. |
Elapsed time: 0.071324057 seconds |
||
Rate: |
Rate: 1402051.48 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. |
||