@zolern : I'm wondering too why the original nim version is that slow.

Using the windows version of nim on my computer (i7-6650, 3.60GHz, Windows 10 
Pro 64-bit) is already faster at running my version of the program (see below) 
then running it under _windows/bash/ubuntu_ (what I did before). The same is 
true for the _Julia_ version.

Using _clang_ instead of _gcc_ makes it almost 3x faster. Since _Julia_ is 
using _LLVM_, probably the _clang_ version uses the same (faster?) library 
functions. I'm not sure ...

**clang version on windows/mingw**: 
    
    
    nim c -r -d:release --cc:clang pi.nim
    ...
    Elapsed time: 2.055
    Pi: 3.141592663589326
    

**gcc version on windows/mingw**: 
    
    
    nim c -r -d:release pi.nim
    ...
    Elapsed time: 5.909
    Pi: 3.141592663589326
    

**pi.nim**: 
    
    
    import times, math
    
    proc `/`(a, b: int): float =
      float(a) / float(b)
    
    proc leibniz(terms: int): float =
      for i in 0 .. terms:
        result += ((-1)^i) / (2*i+1)
      result *= 4.0
    
    let
      t0 = cpuTime()
      pi = leibniz(100_000_000)
      tt = cpuTime() - t0
    echo("Elapsed time: ", tt)
    echo("Pi: ", pi)
    

Reply via email to