/ bench / commonBench.nim
commonBench.nim
 1  import stopwatch
 2  
 3  template multiBench*(nanosecs: int64, times: int, body: stmt): stmt =
 4      assert(times mod 2 == 0)
 5      var arr: array[0..times - 1, int64]
 6      for i in countup(0, times - 1):
 7          var c: clock
 8          bench(c):
 9              body
10          arr[i] = c.nanoseconds()
11      sort(arr, cmp)
12      # ignore lowest and highest 10%
13      let tenth: int = times div 10
14      let lowest = arr[tenth]
15      var totaldiff = 0.int64
16      for i in countup(tenth + 1, times - tenth - 1):
17          totaldiff += arr[i] - lowest
18      nanosecs = lowest + totaldiff div (times - 2 * tenth)