Created
October 19, 2019 23:12
-
-
Save glucn/03905c6832346a6febd683ade4d8cab7 to your computer and use it in GitHub Desktop.
Benchmark for append()
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 | |
var size = 1 << 20 | |
func Append() { | |
var s []int | |
for i := 0; i < size; i++ { | |
s = append(s, i) | |
} | |
_ = s | |
} | |
func Make() { | |
s := make([]int, size) | |
for i := 0; i < size; i++ { | |
s[i] = i | |
} | |
_ = s | |
} |
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 "testing" | |
func BenchmarkAppend(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
Append() | |
} | |
} | |
func BenchmarkMake(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
Make() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment