Advertisement
Guest User

Untitled

a guest
May 26th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. package slices
  2.  
  3. import (
  4. "testing"
  5. )
  6.  
  7. var length = 10000
  8.  
  9. func BenchmarkAppend(b *testing.B) {
  10. for i := 0; i < b.N; i++ {
  11. Append()
  12. }
  13. }
  14.  
  15. func BenchmarkAppendFixed(b *testing.B) {
  16. for i := 0; i < b.N; i++ {
  17. AppendFixed()
  18. }
  19. }
  20.  
  21. func Append() {
  22. var b []int
  23. for i := 0; i < length; i++ {
  24. b = append(b, i)
  25. }
  26. }
  27. func AppendFixed() {
  28. b := make([]int, 0, length)
  29.  
  30. for i := 0; i < length; i++ {
  31. b = append(b, i)
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement