Rate counter: Difference between revisions

Added Chipmunk Basic
(added Arturo)
(Added Chipmunk Basic)
 
(4 intermediate revisions by 4 users not shown)
Line 551:
return 0;
}</syntaxhighlight>
 
=={{header|Chipmunk Basic}}==
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 for i = 1 to 3
120 gosub 170
130 next i
140 i = 200
150 gosub 170
160 end
170 'function timeit
180 iter = 0
190 starter = timer
200 while true
210 iter = iter+1
220 if timer >= starter+i then exit while
230 wend
240 print iter;" iteraciones en ";i;" milisegundo";
250 if i > 1 then print "s" else print ""
260 return</syntaxhighlight>
 
=={{header|Common Lisp}}==
Line 801 ⟶ 821:
theJob()
})</syntaxhighlight>
 
=={{header|EasyLang}}==
[https://easylang.dev/show/#cod=RYzLCsIwEEX3+YpDF+IDyygUV+m/hDZCIA9JB8G/l4SKm8sc5ty7lFgqDxFTMi6H5NQbYIne1XZUt3KxyHhvlMrbMwmTdCnUJfqmNArPLs/7c+9aOo0tFMv22TQkvxdUmPnprxqychMRzhyVKyonDgykbfiPCBY1Pq/mCw== Run it]
<syntaxhighlight>
color 700
on animate
clear
rad += 0.2
move 50 50
circle rad
if rad > 50
rad = 0
.
t = systime
if t0 > 0
print 1000 * (t - t0) & " ms"
.
t0 = t
end
</syntaxhighlight>
{{out}}
<pre>
17.00 ms
17.00 ms
16.00 ms
.
.
</pre>
 
=={{header|Erlang}}==
Line 1,181 ⟶ 1,229:
return times;
}</syntaxhighlight>
 
=={{header|jq}}==
'''Works with jq and gojq, that is, the C and Go implementations of jq.'''
 
In this entry, the times to compute `x*x*x` are compared with the times to compute `pow(x;3)`.
 
Note that jq only has direct access to the system clock ("now").
<syntaxhighlight lang=jq>
def cube: . * . * .;
 
def pow3: pow(.; 3);
 
def benchmark($n; func; $arg; $calls):
reduce range(0; $n) as $i ([];
now as $_
| (range(0; $calls) | ($arg | func)) as $x
# milliseconds:
| . + [(now - $_) * 1000 | floor] ) ;
 
"Timings (total elapsed time in milliseconds):",
"cube pow3",
([benchmark(10; cube; 5; 1e5), benchmark(10; pow3; 5; 1e5)]
| transpose[]
| "\(.[0]) \(.[1])" )
</syntaxhighlight>
'''Invocation''': jq -nr -f rate-counter.jq
{{{output}}
<pre>
Timings (total elapsed time in milliseconds):
cube pow3
205 178
164 182
182 156
173 173
167 154
181 175
180 176
176 160
186 206
173 174
</pre>
 
 
=={{header|Jsish}}==
Line 1,824 ⟶ 1,914:
sub factorial($n) { (state @)[$n] //= $n < 2 ?? 1 !! $n * factorial($n-1) }
 
runrate 10000100_000, { state $n = 1; factorial($n++) }
 
runrate 10000100_000, { state $n = 1; factorial($n++) }</syntaxhighlight>
{{out}}
<pre>Start time: 20132023-0304-08T2019T08:5723:02Z50.276418Z
End time: 20132023-0304-08T2019T08:5723:03Z54.716864Z
Elapsed time: 14.5467497440445313 seconds
Rate: 646522520.1726 per second
 
Start time: 20132023-0304-08T2019T08:5723:03Z54.726913Z
End time: 20132023-0304-08T2019T08:5723:04Z54.798238Z
Elapsed time: 0.7036318071324057 seconds
Rate: 142111402051.9848 per second</pre>
</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.
 
Line 2,364 ⟶ 2,455:
 
Note that, in an attempt to obtain more meaningful times, I've called the function 1 million times compared to just one in the Kotlin example which uses a more accurate timer.
<syntaxhighlight lang="ecmascriptwren">var cube = Fn.new { |n| n * n * n }
 
var benchmark = Fn.new { |n, func, arg, calls|
2,122

edits