Created
November 30, 2011 17:39
-
-
Save jpedrosa/1409959 to your computer and use it in GitHub Desktop.
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
$ 8g append.go && 8l -o goappend append.8 && time ./goappend | |
Elapsed time: 0.18 | |
1.5000704643886663e+07 | |
real 0m4.944s | |
user 0m4.664s | |
sys 0m0.236s | |
$ cat append.go | |
package main | |
import ( | |
"fmt" | |
"rand" | |
"time" | |
) | |
const _LIST_SIZE int64 = 30000000 | |
func main() { | |
nn := make([]float64, _LIST_SIZE) | |
for i := int64(0); i < _LIST_SIZE; i++ { | |
nn[i] = rand.Float64() | |
} | |
sum := float64(0.0) | |
time1 := time.Nanoseconds() | |
for _, v := range nn { | |
sum += v | |
} | |
elapsed := float32(time.Nanoseconds() - time1) / 1e9 | |
fmt.Printf("Elapsed time: %.2f\n", elapsed) | |
fmt.Println(sum) | |
} | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment