Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "testing"
- "github.com/Vivino/go-api/app/helpers"
- )
- func BenchmarkSetSlice(b *testing.B) {
- s := helpers.NewSet32()
- for n := 0; n < b.N; n++ {
- s.Add(uint32(n))
- }
- foo := s.Slice()
- foo = foo
- }
- func BenchmarkHelperNativeSlicePreAlloc(b *testing.B) {
- s := make([]int, b.N)
- for n := 0; n < b.N; n++ {
- s[n] = n
- }
- }
- func BenchmarkHelperNativeSliceNoPreAlloc(b *testing.B) {
- var s []int
- for n := 0; n < b.N; n++ {
- s = append(s, n)
- }
- }
- /*
- $ go test -bench=. slice_test.go -benchmem=true
- 2018/03/12 14:15:19 DEBUG Now using Go's stdlib log package (via loggers/mappers/stdlib).
- goos: linux
- goarch: amd64
- BenchmarkSetSlice-4 10000000 274 ns/op 29 B/op 0 allocs/op
- BenchmarkHelperNativeSlicePreAlloc-4 1000000000 3.16 ns/op 8 B/op 0 allocs/op
- BenchmarkHelperNativeSliceNoPreAlloc-4 300000000 4.52 ns/op 40 B/op 0 allocs/op
- PASS
- ok command-line-argumentsfalse8.625s
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement