Skip to content

Instantly share code, notes, and snippets.

@jackmott
Last active August 28, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmott/39669cad1321d4f1be476683573b899c to your computer and use it in GitHub Desktop.
Save jackmott/39669cad1321d4f1be476683573b899c to your computer and use it in GitHub Desktop.
go test
package main
import "fmt"
import "time"
func main() {
var values [32000000]float64
for i := 0; i < len(values); i++ {
values[i] = 2.0
}
for j := 0; j < 10; j++ {
start := time.Now().UnixNano()
sum := 0.0
for i := 0; i < len(values); i++ {
v := values[i]
sum = sum + v*v
}
end := time.Now().UnixNano()
fmt.Printf("forloop sum %f time: %d\n",sum, (end-start)/1000000)
start = time.Now().UnixNano()
sum = 0.0
for _,v := range values {
sum = sum + v*v
}
end = time.Now().UnixNano()
fmt.Printf("range sum %f time: %d\n",sum, (end-start)/1000000)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment