Time a function: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎Insitux: implementation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 4 users not shown)
Line 1,123:
println(`Counting to $count takes ${(finish-start)//1000000}ms`)
}</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
func fua lim .
# this is interpreted
i = 1
while i <= lim
sum += i
i += 1
.
return sum
.
start = systime
print fua 1e8
print systime - start
#
fastfunc fub lim .
# this is compiled to wasm
i = 1
while i <= lim
sum += i
i += 1
.
return sum
.
start = systime
print fub 1e8
print systime - start
</syntaxhighlight>
 
=={{header|Elena}}==
{{trans|C#}}
ELENA 46.x :
<syntaxhighlight lang="elena">import system'calendar;
import system'routines;
Line 1,137 ⟶ 1,166:
threadControl.sleep(1000);
new Range(0,10000).filterBy::(x => x.mod:(2) == 0).summarize();
}
Line 2,378 ⟶ 2,407:
[2.7, 2.8, 31.4, 38.1, 58.0, 76.2, 100.5, 130.0, 149.3, 180.0]
using ''qsort()'' from [[Quicksort#Python|Quicksort]]. Timings show that the implementation of ''qsort()'' has quadratic dependence on sequence length ''N'' for already sorted sequences (instead of ''O(N*log(N))'' in average).
 
=={{header|Quackery}}==
 
<code>time</code> returns system time since Unix epoch in microseconds, but is not reliable to the microsecond, so we are using millisecond granularity. Process time is not available.
 
<syntaxhighlight lang="Quackery"> [ time ]'[ do
time swap - 1000 / ] is time: ( --> n )
 
time: [ 0 314159 times 1+ echo ]
cr cr
say "That took about " echo say " milliseconds."</syntaxhighlight>
 
{{out}}
 
<pre>314159
 
That took about 392 milliseconds.
</pre>
 
=={{header|R}}==
Line 2,563 ⟶ 2,610:
#11CAh SYSEVAL tick -
B→R 8192 / 1 FIX RND STD
≫ ≫ '<span style="color:blue">TEVAL</span>''TIMER'''’ STO
|
'''TIMER'''<span style="color:blue">TEVAL</span> ''( ≪function≫ -- execution_time )''
Store current system time
Execute function
Line 2,574 ⟶ 2,621:
{{in}}
<pre>
≪ 1 1000 START NEXT ≫ TIMERTEVAL
</pre>
{{out}}
Line 2,580 ⟶ 2,627:
1: 6.4
</pre>
Yes, more than 6 seconds to loop 1000 times is quite slow.
 
HP-49+ models have a built-in <code>TEVAL</code> command.
 
=={{header|Ruby}}==
Line 3,030 ⟶ 3,079:
{{libheader|Wren-check}}
The only way Wren currently has to time a function (encapsulated in the ''Benchmark.run'' method) 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.
<syntaxhighlight lang="ecmascriptwren">import "./check" for Benchmark
 
Benchmark.run("a function", 100, true) {
9,476

edits