Hi, I'm attempting to optimize pair-wise operations over arrays of big integers ('vectorize'). Currently, I tried creating two versions of a point-wise multiplication function - one that is a simple serial for-loop, and another that uses go-routines to create a parallel (or more correctly - concurrent) for loop. The code is below along with the results, showing that the parallel for loop is actually ~10x slower.
My question is - is there a better way to achieve this, or is a naive serial for-loop the best one can hope for? func BenchmarkLoop(b *testing.B) { var x, y, z [10000]big.Int for i := 0; i < 10000; i++ { x[i].SetInt64(892745680) y[i].SetInt64(353322197) } for n := 0; n < b.N; n++ { for i := 0; i < 10000; i++ { z[i].Mul(&x[i], &y[i]) } } } func BenchmarkParLoop1(b *testing.B) { var x, y, z [10000]big.Int runtime.GOMAXPROCS(4) // Tried playing with this value from 1-8 for i := 0; i < 10000; i++ { x[i].SetInt64(892745680) y[i].SetInt64(353322197) } for n := 0; n < b.N; n++ { for i := 0; i < 10000; i++ { go func(i int) { z[i].Mul(&x[i], &y[i]) }(i) } } } Benchmarks: BenchmarkLoop-8 5000 350033 ns/op BenchmarkParLoop1-8 500 2352201 ns/op Thanks! -- 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.