Skip to content

Instantly share code, notes, and snippets.

@RedBeard0531
Created December 19, 2017 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedBeard0531/0a1ebf92fd7c861dec1ee9b21c795827 to your computer and use it in GitHub Desktop.
Save RedBeard0531/0a1ebf92fd7c861dec1ee9b21c795827 to your computer and use it in GitHub Desktop.
import tables
import critbits
import os
import sequtils
import times
import random
import xxhash
#import murmur
import murmur3
import hashes
var t = times.cpuTime()
template printTime() =
let newTime = times.cpuTime()
echo newTime - t
t = newTime
type XXS = distinct string
#randomize()
var words = toSeq(paramStr(1).lines).mapIt(it.XXS)
printTime()
#shuffle(words)
printTime()
for w in words.mitems: shallow(w.string)
printTime()
#proc hash(xxs: XXS): Hash {.borrow.}
proc hash(xxs: XXS): Hash = XXH64(xxs.string).int
#proc hash(xxs: XXS): Hash = murmur.hash(xxs.string).int
#proc hash(xxs: XXS): Hash = murmur_hash(xxs.string)[0].int
proc `==`(x, y: XXS): bool {.borrow.}
when true:
echo "CritBit:"
var counts2: CritBitTree[int]
for i in 1..10:
for w in words: counts2.inc w.string
printTime()
else:
echo "Table:"
var counts1 = initCountTable[XXS]()
for i in 1..10:
for w in words: counts1.inc w
printTime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment