Skip to content

Instantly share code, notes, and snippets.

@GULPF
GULPF / stats.txt
Created April 28, 2018 22:05
Nim stdlib usage for top 1000 starred GitHub projects
Number of files that imports the module (~15000 files total)
1 oswalkdir
1 rstgen
1 ftpclient
1 distros
1 strmisc
2 rlocks
2 lenientops
2 unidecode
3 httpserver
import random, times
var input = newSeq[string]()
for _ in 1..100_000:
input.add(fromUnix(rand(0..100_000_000)).utc.format("yyyy-MM-dd'T'HH:mm:sszzz"))
block:
var sum = 0'i64
let before = getTime()
for str in input:
import typetraits
iterator foo(i: int): int {.closure.} =
yield i + 1
yield i + 2
let f = foo
echo f(1) # 2
echo f(2) # 4
NOTE: The imports are found by simple walking throught the AST and looking after `nkFromStmt` and `nkImportStmt` nodes.
The stdlib modules are identified by simple string comparisions.
This method is not entirely accurate, but it does give some indication of which modules are used and which are not.
File imports (tot: 14078)
0 volatile
0 db_odbc
0 asyncftpclient
0 punycode
0 ssl
proc foo(x: int8) = discard
proc bar(x: range[0'i8..1'i8]) = discard
var x = 1.int
echo compiles(foo(x)) # false
echo compiles(bar(x)) # true