I was reading this: `Golang's Real-time GC in Theory and Practice
<https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/>`_ and
thought I'd try the same code in Nim.
Here my initial cut, anyone see anything that should be changed/improved to
make the benchmark more comparable/meaningful?
```nim
# run with 'nim -c -r -d:release bm.nim'
import strutils
import times
const windowSize = 200000
const msgCount = 1000000
type msg = ref array[1024, byte]
type buffer = ref array[windowSize, msg]
var worst: float
proc mkMessage( n: int ): msg =
result = new( msg )
for i in items( result[] ):
result[i] = byte( n )
proc pushMsg( b: var buffer, highID: int ) =
let start = cpuTime()
let m = mkMessage( highID )
b[highID mod windowSize] = m
let elapsed = cpuTime() - start
if elapsed > worst:
worst = elapsed
proc main() =
var b = new( buffer )
for i in 0..<msgCount:
pushMsg( b, i )
let worst_ms = formatFloat( worst*1000, format=ffDecimal, precision=2 )
echo( "Worst push time: ", worst_ms, "ms" )
when isMainModule:
main()
```
I also don't know enough about the various garbage collectors to ID which would
produce the best numbers but I thought that would be good information to
include in the top comment block, e.g. something like:
```nim
# Try with nim -c -r -d:release --gc:stack bm.nim for best performance!
```
Once there are no concerns/objections I'll submit it back to their repo for
inclusion. Thanks!