Last active
January 6, 2020 19:02
-
-
Save Araq/e2874e8b218ca8abf6cfc0c1d3bc0f5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compile and run with 'nim c -r -d:useRealtimeGC -d:release main.nim' | |
import strutils | |
#import times | |
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 ..< result.len: | |
result[i] = byte(n) | |
proc pushMsg(b: var Buffer, highID: int) = | |
let start = getTicks() | |
let m = mkMessage(highID) | |
when not defined(gcDestructors): | |
shallowCopy(b[highID mod windowSize], m) | |
else: | |
# new runtime can move this, no need for 'shallowCopy' | |
b[highID mod windowSize] = m | |
#GC_step(500) # 0.5ms | |
let elapsed = getTicks() - start | |
if elapsed > worst: | |
worst = elapsed | |
proc main() = | |
#GC_disable() | |
when not defined(gcDestructors): | |
GC_setMaxPause(100) | |
GC_disableMarkAndSweep() | |
var b = newSeq[Msg](windowSize) | |
for i in 0 ..< msgCount: | |
pushMsg(b, i) | |
# nano seconds into ms: | |
echo("Worst push time: ", worst.float / 1000_000.0, "ms") | |
when isMainModule: | |
main() | |
echo(GC_getStatistics()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment