Using exponentiation just for interlacing 1, -1, 1, -1, ... is pointless (apart
from mathematical formulas on paper) and should not be done, so no matter if
some compiler optimizes it.
My copy just arrived today. Will start to read it later today.
@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
I am still confused that Nim's pow is so unexpectedly slow: Nim just calls C
library function pow from , wtf?
Anyway, last edition (without pow) is just fast & furious And Nim is awesome,
no doubt!
Our **lovely Nim** is outstanding !
Well as I found out, my Book is on the way, too. Yay. Well you did not get my
feedback during the development of the Book, but I think you will get my
feedback when I read it. Then you can use it for revision 1
Write a game
Wow, final "ready for print" edition is pretty awesome. Great work!
I am pretty sure that Julias's POW takes care that first argument is -1 and
optimized it with something like MOD You can check it, I suppose that modified
Julia code with MOD will take pretty same time as code with POW.
@zolern, thank you. Your code rocks.
However, we are cheating Julia because in her code there is a **POW** instead
**MOD**.
I will modify / rerun the .jl script just to check the result.
Well, my 10 cents
import times, math
proc leibniz(terms: int): float =
var res = 0.0
for n in 0..terms:
res = res + (if n mod 2 == 0: 1.0 else: -1.0) / float(2 * n + 1)
return 4*res
let t0 = cpuTime()
echo(leibniz(100_000_0
Julia compiles with `-march=native` by default so try passing
`--passC:"-march=native"` to Nim. I have this in my `~/.config/nim.cfg` along
with `--passC:"-flto"` (for release mode).
It seems that Julia JIT is aware of SSE extensions and it uses them. GCC or
MSVC should be emitting them too, but it depends on C code
Thank you all.
@wiffel/Nibbler, in my Julia test, I was using Pro version 0.6.1 64 bit running
on Windows 10.
Now, running the same .jl code on a Windows 8 64 bit (i5 CPU 650 @ 3.20GHz,
3193 Mhz, 2 Cores, 4 Processors) I got the following:
2.763225 seconds (1.77 k allocations: 95.
I compiled the same approximate version to C with gcc optimisations on, and
found the execution time to be roughly comparable between Nim and C. Could
Julia's JIT be doing some sort of optimisation that shortcuts the full code
somehow?
With the Nim version:
import times, math
@alfrednewman
I tried to replicate your test. On my computer the following (slightly modified
version) of the _nim_ program and the _julia_ program have the same runtime.
Whatever I do, I fail to run the _julia_ version in less than 2 seconds (as you
had). Are you sure that test went OK?
At least so: `res += float([1,-1][n mod 2])/(2.0*float(n)+1.0)`.
That call to `pow` to change sign may be a possible reason of slowdown.
Hello,
How can I optimize the speed of the following proc:
import times, math
proc leibniz(terms: int): float =
var res = 0.0
for n in 0..terms:
res += pow(-1.0,float(n))/(2.0*float(n)+1.0)
return 4*res
let t0 = cpuTime()
echo
Great Job !! Mine is on the way !
All the best.
20 matches
Mail list logo