github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/pool/bench_realloc-vs-empty_test.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package pool 4 5 import ( 6 "testing" 7 ) 8 9 /* 10 goos: windows 11 goarch: amd64 12 cpu: Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz 13 14 poolLen:10000 15 BenchmarkRealloc-8 55225 23272 ns/op 81922 B/op 1 allocs/op 16 BenchmarkEmpty-8 31210 51066 ns/op 10 B/op 0 allocs/op 17 18 poolLen:100000 19 BenchmarkRealloc-8 5335 212914 ns/op 802969 B/op 1 allocs/op 20 BenchmarkEmpty-8 2919 412944 ns/op 1100 B/op 0 allocs/op 21 22 poolLen:300000 23 BenchmarkRealloc-8 2193 590969 ns/op 2401359 B/op 1 allocs/op 24 BenchmarkEmpty-8 508 2448291 ns/op 18899 B/op 0 allocs/op 25 */ 26 27 const poolLen = 300000 28 29 func BenchmarkRealloc(b *testing.B) { 30 var pool1 = make([]interface{}, poolLen/2) 31 for n := 0; n < b.N; n++ { 32 var pool2 = pool1 33 pool1 = make([]interface{}, poolLen/2) 34 _ = pool1[0] 35 _ = pool2[0] 36 } 37 } 38 39 func BenchmarkEmpty(b *testing.B) { 40 var pool1 = make([]interface{}, poolLen) 41 var pool2 = make([]interface{}, poolLen) 42 for n := 0; n < b.N; n++ { 43 copy(pool2, pool1) 44 for i := 0; i < poolLen/2; i++ { 45 pool2[i] = nil 46 } 47 _ = pool1[0] 48 _ = pool2[0] 49 for i := 0; i < poolLen/2; i++ { 50 pool1[i] = nil 51 } 52 } 53 }