Anonymous user
Time a function: Difference between revisions
Updated to work with Nim 1.4: added missing parameter type, replaced "stmt" with "untyped", replaced "expr" with "float". Also removed "echo" in proc "doWork". Other changes.
Alextretyak (talk | contribs) (Added 11l) |
(Updated to work with Nim 1.4: added missing parameter type, replaced "stmt" with "untyped", replaced "expr" with "float". Also removed "echo" in proc "doWork". Other changes.) |
||
Line 1,635:
=={{header|Nim}}==
<lang nim>import times,
proc doWork(x: int) =
var n = x
for i in 0..10000000:
n += i
▲template time(s: stmt): expr =
let t0 = cpuTime()
statement
cpuTime() - t0
echo "Time = ", time(doWork(100)).formatFloat(ffDecimal, precision = 3), " s"</lang>
{{out}}
Compiled in debug mode (no options).
<pre>
=={{header|OCaml}}==
|