Rate counter: Difference between revisions

added D language
No edit summary
(added D language)
Line 397:
Call the <code>time-this</code> macro to excute a loop 99 times:
<lang lisp>(print (time-this 99 (loop for i below 10000 sum i)))</lang>which gives a pair of numbers, the real time and the run time, both in seconds:<lang>(0.023 0.022)</lang>
 
=={{header|D}}==
 
<lang d>
import std.stdio;
import std.conv;
import std.datetime.stopwatch;
 
int a;
void f0() {}
void f1() { auto b = a; }
void f2() { auto b = to!string(a); }
 
void main()
{
auto r = benchmark!(f0, f1, f2)(10_000);
 
writeln("Time fx took to run 10,000 times:\n");
writeln("f0: ", r[0]);
writeln("f1: ", r[1]);
writeln("f2: ", r[2]);
}
 
</lang>
 
{{out}}
<pre>
Time fx took to run 10,000 times:
 
f0: 37 μs and 7 hnsecs
f1: 56 μs and 2 hnsecs
f2: 1 ms, 966 μs, and 6 hnsecs
 
</pre>
 
 
=={{header|E}}==
Anonymous user