Time a function: Difference between revisions

Added Wren
(+ Janet)
(Added Wren)
Line 2,504:
30000/1000000 # in microseconds
=> 2</lang>
 
=={{header|Wren}}==
The only way Wren currently has to time a function is to measure the System time before and after the function is called. We therefore use that approach, averaging over say 100 runs, having first shut down as many other processes as we can.
<lang ecmascript>var f = Fn.new {
for (i in 0..1e7) {}
}
 
var runs = 100
var total = 0
for (i in 1..runs) {
var start = System.clock
f.call()
total = total + System.clock - start
}
System.print("Over %(runs) runs, took an average of %(total/runs) seconds.")</lang>
 
{{out}}
<pre>
Over 100 runs, took an average of 0.19607459 seconds.
</pre>
 
=={{header|XPL0}}==
9,487

edits