Skip to content

Instantly share code, notes, and snippets.

@jpedrosa
Created November 30, 2011 17:39
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 jpedrosa/1409959 to your computer and use it in GitHub Desktop.
Save jpedrosa/1409959 to your computer and use it in GitHub Desktop.
$ 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