Last active
August 28, 2016 12:25
-
-
Save jackmott/39669cad1321d4f1be476683573b899c to your computer and use it in GitHub Desktop.
go test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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