As mentioned in another thread, Python memoizes the hash value for strings, 
which yields faster processing for Set operations.

You can easily do this yourself with Nim by creating an object with the 
pre-computed hash value:
    
    
    type
      HString = object
        str: string
        hash: Hash
    

and supplying a corresponding hash proc:
    
    
    proc hash(str: HString): Hash =
      str.hash
    

Using those, the Nim version becomes ~20% faster than the Python version on my 
system.

Full code example: 
[https://gist.github.com/aboisvert/2daf9ed487214d810e0689d3e3a3714f](https://gist.github.com/aboisvert/2daf9ed487214d810e0689d3e3a3714f)

Reply via email to