( Yeah, it's a tiny tiny program from someone's language comparison <http://www.hildstrom.com/projects/langcomp/index.html#:~:text=Results%20Table%20%20%20%20%20%20,%20%20225.9%20%2016%20more%20rows%20> but this is a hugely bigger slowdown than gcc or java?
The code change is compile time constant — array_length int = 100000000 — changed to run time value — array_length int = 1000000 * iterations ) package main import "os" import "fmt" import "strconv" func main() { var ( element, iteration, iterations, innerloop int sum float64 ) if len(os.Args) > 1 { iterations,_ = strconv.Atoi(os.Args[1]) } fmt.Printf("iterations %d\n", iterations) var ( array_length int = 100000000 array []float64 = make([]float64, array_length) ) for element = 0; element < array_length; element++ { array[element] = float64(element) } for iteration = 0; iteration < iterations; iteration++ { for innerloop = 0; innerloop < 1000000000; innerloop++ { sum += array[(iteration + innerloop) % array_length] } } fmt.Printf("sum %E\n", sum) array = nil } $ /opt/src/go1.16/go/bin/go build -o out test.go $ time ./out 100 iterations 100 sum 5.000000E+18 real 3m3.225s ==== package main import "os" import "fmt" import "strconv" func main() { var ( element, iteration, iterations, innerloop int sum float64 ) if len(os.Args) > 1 { iterations,_ = strconv.Atoi(os.Args[1]) } fmt.Printf("iterations %d\n", iterations) var ( array_length int = 1000000 * iterations array []float64 = make([]float64, array_length) ) for element = 0; element < array_length; element++ { array[element] = float64(element) } for iteration = 0; iteration < iterations; iteration++ { for innerloop = 0; innerloop < 1000000000; innerloop++ { sum += array[(iteration + innerloop) % array_length] } } fmt.Printf("sum %E\n", sum) array = nil } $ /opt/src/go1.16/go/bin/go build -o out test.go $ time ./out 100 iterations 100 sum 5.000000E+18 real 18m20.737s -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/400499cb-8da4-4b73-b296-200d0fe70dd4n%40googlegroups.com.