Jump to content

Rate counter: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
No edit summary
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 11:
 
'''See also:''' [[System time]], [[Time a function]]
 
 
=={{header|Ada}}==
Line 433 ⟶ 432:
 
</pre>
 
 
=={{header|E}}==
Line 1,006 ⟶ 1,004:
end function
</lang>
 
=={{header|Mathematica}}==
The first parameter for both of these functions can be any program code.
 
<lang>jobRateCounted[fn_,Y_Integer]:=First[AbsoluteTiming[Do[fn,{Y}]]/Y;
SetAttributes[jobRateCounted,HoldFirst]
 
jobRatePeriod[fn_,time_]:=Block[{n=0},TimeConstrained[While[True,fn;n++]];n/time];
SetAttributes[jobRatePeriod,HoldFirst]</lang>
 
=={{header|OxygenBasic}}==
Line 1,129 ⟶ 1,136:
'Sunday July 01 2012
</lang>
 
=={{header|Mathematica}}==
The first parameter for both of these functions can be any program code.
 
<lang>jobRateCounted[fn_,Y_Integer]:=First[AbsoluteTiming[Do[fn,{Y}]]/Y;
SetAttributes[jobRateCounted,HoldFirst]
 
jobRatePeriod[fn_,time_]:=Block[{n=0},TimeConstrained[While[True,fn;n++]];n/time];
SetAttributes[jobRatePeriod,HoldFirst]</lang>
 
=={{header|PARI/GP}}==
Line 1,167 ⟶ 1,165:
A negative COUNT will run each job for at least COUNT seconds.<br>
A positive COUNT will run each job COUNT times.
=={{header|Perl 6}}==
<lang perl6>sub runrate($N where $N > 0, &todo) {
my $n = $N;
 
my $start = now;
todo() while --$n;
my $end = now;
 
say "Start time: ", DateTime.new($start).Str;
say "End time: ", DateTime.new($end).Str;
my $elapsed = $end - $start;
 
say "Elapsed time: $elapsed seconds";
say "Rate: { ($N / $elapsed).fmt('%.2f') } per second\n";
 
sub factorial($n) { (state @)[$n] //= $n < 2 ?? 1 !! $n * factorial($n-1) }
 
runrate 10000, { state $n = 1; factorial($n++) }
 
runrate 10000, { state $n = 1; factorial($n++) }</lang>
{{out}}
<pre>Start time: 2013-03-08T20:57:02Z
End time: 2013-03-08T20:57:03Z
Elapsed time: 1.5467497 seconds
Rate: 6465.17 per second
 
Start time: 2013-03-08T20:57:03Z
End time: 2013-03-08T20:57:04Z
Elapsed time: 0.7036318 seconds
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.
 
=={{header|Phix}}==
Line 1,468 ⟶ 1,434:
#t
</pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>sub runrate($N where $N > 0, &todo) {
my $n = $N;
 
my $start = now;
todo() while --$n;
my $end = now;
 
say "Start time: ", DateTime.new($start).Str;
say "End time: ", DateTime.new($end).Str;
my $elapsed = $end - $start;
 
say "Elapsed time: $elapsed seconds";
say "Rate: { ($N / $elapsed).fmt('%.2f') } per second\n";
 
sub factorial($n) { (state @)[$n] //= $n < 2 ?? 1 !! $n * factorial($n-1) }
 
runrate 10000, { state $n = 1; factorial($n++) }
 
runrate 10000, { state $n = 1; factorial($n++) }</lang>
{{out}}
<pre>Start time: 2013-03-08T20:57:02Z
End time: 2013-03-08T20:57:03Z
Elapsed time: 1.5467497 seconds
Rate: 6465.17 per second
 
Start time: 2013-03-08T20:57:03Z
End time: 2013-03-08T20:57:04Z
Elapsed time: 0.7036318 seconds
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.
 
=={{header|REXX}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.