Created
June 13, 2020 08:01
-
-
Save marnix/48cbcb00ced295c3e182c765f4a74939 to your computer and use it in GitHub Desktop.
Reproduction scenario for nim --gc:arc performance difference
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
import memfiles | |
import streams | |
proc mmapStream(mmFileName: string): Stream = | |
return newMemMapFileStream(mmFileName) | |
iterator tokens(mmfile: Stream): string = | |
var i,j = 0 | |
while not mmfile.atEnd(): | |
let c = mmfile.readChar() | |
if c <= chr(32): | |
if i < j: | |
mmfile.setPosition(i) | |
let s = mmfile.peekStr(j-i) | |
yield s | |
mmfile.setPosition(j+1) | |
i = j+1 | |
inc j | |
when isMainModule: | |
proc test(): void = | |
var n = 0 | |
var l = 0 | |
let mmStream = mmapStream("set.mm") | |
defer: mmstream.close() | |
for t in tokens(mmStream): | |
l += len(t) | |
inc n | |
echo(n," ",l) | |
test() |
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
#!/bin/bash -xe | |
if [ ! -f set.mm ] | |
then | |
curl --location https://github.com/metamath/set.mm/raw/b0925f0afd5963577ea76b252cb6613c885b393d/set.mm > set.mm | |
fi | |
nim c --opt:speed -d:release arcperfdiff && time ./arcperfdiff | |
nim c --gc:arc --opt:speed -d:release arcperfdiff && time ./arcperfdiff | |
# both should output | |
# | |
# 4961591 29826787 | |
# | |
# but with nim 1.2.0 binaries from nixpkgs, for me | |
# the default version takes ~1 second, | |
# while the --gc:arc version takes 5+ seconds. |
Thanks! Is there a GitHub issue for this, or should I create one?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile with -d:danger instead of -d:release, there's still a ton of boundary checks in the inner loop causing slow downs.