Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ 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