package main

import (
    "testing"
)

const N = 1024 * 1024 // number of elements
type Element int64
var x = make([]Element, N)
var y []Element


func Benchmark_CloneWithAppend(b *testing.B) {
    for i := 0; i < b.N; i++ {
        y = append([]Element(nil), x...)
    }
}

func Benchmark_CloneWithCopy(b *testing.B) {
    b.ResetTimer()
    for i := 0; i < b.N; i++ {
        t := make([]Element, N)
        copy(t, x)
        y = t
    }
}

/*
$ go test -bench=.
Benchmark_CloneWithAppend-4           2000        738281 ns/op
Benchmark_CloneWithCopy-4             1000       1822462 ns/op
*/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to