Hi

Exploring Go, 1st project is to port over my favourite playground (prime 
number factorisation) from Python to Go.

Aside: I was a big Oberon-2 fan back in the day, so I'm pretty excited 
about Go making possible what never was in Oberon.  

Back to business: I was disappointed that Go is only a factor of 3 or so 
faster than Python.  The numbers I'm dealing with are big enough that they 
don't fit into a uint64 so I'm using math/big ... turns out that about 70% 
of the runtime is spent in the Mod function of math/big, and mostly this is 
inside the underlying function divLarge. See profile info below.   

The naive explanation would be that Mod in Go math/big is about just as 
fast as the % primitive in python (Python has big integers automatically 
where needed) but the rest of the program is a factor of 10 or so faster in 
Go than Python.  I wonder though, especially if there is a better way to 
take a Mod.  The numbers are not THAT large (less than 100 decimal digits 
in most cases) ...

(pprof) top10 -cum
13.01s of 41.11s total (31.65%)
Dropped 86 nodes (cum <= 0.21s)
Showing top 10 nodes out of 74 (cum >= 6.66s)
      flat  flat%   sum%        cum   cum%
         0     0%     0%     40.45s 98.39%  runtime.goexit
         0     0%     0%     40.20s 97.79%  main.main
         0     0%     0%     40.20s 97.79%  runtime.main
     0.28s  0.68%  0.68%     40.19s 97.76% 
 _/Users/templon/gofact/factoring.Mybrent
         0     0%  0.68%     40.19s 97.76% 
 _/Users/templon/gofact/factoring.Trial_n_X
     0.44s  1.07%  1.75%     29.42s 71.56%  math/big.(*Int).Mod
     0.77s  1.87%  3.62%     28.98s 70.49%  math/big.(*Int).QuoRem
     0.51s  1.24%  4.86%     28.18s 68.55%  math/big.nat.div
    10.39s 25.27% 30.14%     27.47s 66.82%  math/big.nat.divLarge
     0.62s  1.51% 31.65%      6.66s 16.20%  runtime.makeslice

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to