all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
27
Task/Time-a-function/D/time-a-function-2.d
Normal file
27
Task/Time-a-function/D/time-a-function-2.d
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import tango.io.Stdout;
|
||||
import tango.time.Clock;
|
||||
|
||||
int identity (int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
int sum (int num)
|
||||
{
|
||||
for (int i = 0; i < 1000000; i++)
|
||||
num += i;
|
||||
return num;
|
||||
}
|
||||
|
||||
double timeIt(int function(int) func, int arg)
|
||||
{
|
||||
long before = Clock.now.ticks;
|
||||
func(arg);
|
||||
return (Clock.now.ticks - before) / cast(double)TimeSpan.TicksPerSecond;
|
||||
}
|
||||
|
||||
void main ()
|
||||
{
|
||||
Stdout.format("Identity(4) takes {:f6} seconds",timeIt(&identity,4)).newline;
|
||||
Stdout.format("Sum(4) takes {:f6} seconds",timeIt(&sum,4)).newline;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue