Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Rate-counter/Nim/rate-counter.nim
Normal file
16
Task/Rate-counter/Nim/rate-counter.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import sugar, std/monotimes, times
|
||||
|
||||
type Func[T] = (T) -> T
|
||||
|
||||
func cube(n: int): int = n * n * n
|
||||
|
||||
proc benchmark[T](n: int; f: Func[T]; arg: T): seq[Duration] =
|
||||
result.setLen(n)
|
||||
for i in 0..<n:
|
||||
let m = getMonoTime()
|
||||
discard f(arg)
|
||||
result[i] = getMonoTime() - m
|
||||
|
||||
echo "Timings (nanoseconds):"
|
||||
for time in benchmark(10, cube, 5):
|
||||
echo time.inNanoseconds
|
||||
Loading…
Add table
Add a link
Reference in a new issue