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 10000, { state $n = 1; factorial($n++) }
runrate 100_000, { state $n = 1; factorial($n++) }


runrate 10000, { state $n = 1; factorial($n++) }</syntaxhighlight>
runrate 100_000, { state $n = 1; factorial($n++) }</syntaxhighlight>
{{out}}
{{out}}
<pre>Start time: 2013-03-08T20:57:02Z
<pre>Start time: 2023-04-19T08:23:50.276418Z
End time: 2013-03-08T20:57:03Z
End time: 2023-04-19T08:23:54.716864Z
Elapsed time: 1.5467497 seconds
Elapsed time: 4.440445313 seconds
Rate: 6465.17 per second
Rate: 22520.26 per second


Start time: 2013-03-08T20:57:03Z
Start time: 2023-04-19T08:23:54.726913Z
End time: 2013-03-08T20:57:04Z
End time: 2023-04-19T08:23:54.798238Z
Elapsed time: 0.7036318 seconds
Elapsed time: 0.071324057 seconds
Rate: 14211.98 per second</pre>
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.