diff --git a/Makefile b/Makefile index 674e78a..7ef6f07 100644 --- a/Makefile +++ b/Makefile @@ -144,3 +144,35 @@ run-d: d analyze-d: @echo "Max Pause: " @cat d.log + +## Nim + +nim: main.nim + nim c -d:release -d:disableMS -d:useRealtimeGC main.nim + +clean:: + rm -f main + rm -r nimcache + +run-nim: nim + ./main > nim.log + cat nim.log + +analyze-nim: + @echo "Worst pause: " + @cat nim.log + +nim-ms: main.nim + nim c -d:release -d:useRealtimeGC main.nim + +clean:: + rm -f main + rm -r nimcache + +run-nim-ms: nim + ./main > nim-ms.log + cat nim-ms.log + +analyze-nim-ms: + @echo "Worst pause: " + @cat nim-ms.log \ No newline at end of file diff --git a/main.nim b/main.nim new file mode 100644 index 0000000..c5fe1e9 --- /dev/null +++ b/main.nim @@ -0,0 +1,59 @@ +# Compile and run with 'nim c -r -d:useRealtimeGC -d:release main.nim' +# See here for more info: http://forum.nim-lang.org/t/2646 + +import strutils + +include "$lib/system/timers" + +const + windowSize = 200000 + msgCount = 1000000 + +type + Msg = seq[byte] + Buffer = seq[Msg] + +var worst: Nanos + +proc mkMessage(n: int): Msg = + result = newSeq[byte](1024) + for i in 0 .. worst: + worst = elapsed + +proc main() = + # Don't use GC_disable() and GC_step(). Instead use GC_setMaxPause(). + when defined(disableMS): + GC_disableMarkAndSweep() + GC_setMaxPause(300) + + var b = newSeq[Msg](windowSize) + # we need to warmup Nim's memory allocator so that not most + # of the time is spent in mmap()... Hopefully later versions of Nim + # will be smarter and allocate larger pieces from the OS: + for i in 0 ..