Jump to content

Rate counter: Difference between revisions

Added Wren
(Added Wren)
Line 1,972:
wc -l .fc 2>/dev/null
rm .fc</lang>
 
=={{header|Wren}}==
{{trans|Kotlin}}
For bench-marking purposes, Wren uses the ''System.clock'' method which returns the number of seconds (to 6 decimal places) since the script was started.
 
The precision of ''System.clock'' is not documented but since it calls C's ''clock()'' function in <timer.h> in the background it will certainly be no more than 1 microsecond and, in practice, resolution may be no better than 10 milliseconds on many systems.
 
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.
<lang ecmascript>var cube = Fn.new { |n| n * n * n }
 
var benchmark = Fn.new { |n, func, arg, calls|
var times = List.filled(n, 0)
for (i in 0...n) {
var m = System.clock
for (j in 0...calls) func.call(arg)
times[i] = ((System.clock - m) * 1000).round // milliseconds
}
return times
}
 
System.print("Timings (milliseconds) : ")
for (time in benchmark.call(10, cube, 5, 1e6)) System.print(time)</lang>
 
{{out}}
Sample run:
<pre>
Timings (milliseconds) :
55
48
45
45
45
45
45
45
45
46
</pre>
 
=={{header|XPL0}}==
9,485

edits

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