github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zarray/slice_bench_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package zarray_test 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/sohaha/zlsgo/zarray" 11 "github.com/sohaha/zlsgo/ztype" 12 ) 13 14 func BenchmarkMap(b *testing.B) { 15 b.Run("Map", func(b *testing.B) { 16 b.RunParallel(func(p *testing.PB) { 17 for p.Next() { 18 zarray.Map(l2, func(i int, v int) string { 19 return ztype.ToString(v) + "//" 20 }) 21 } 22 }) 23 }) 24 25 b.Run("ParallelMap", func(b *testing.B) { 26 b.RunParallel(func(p *testing.PB) { 27 for p.Next() { 28 zarray.ParallelMap(l2, func(i int, v int) string { 29 return ztype.ToString(v) + "//" 30 }, uint(len(l2))) 31 } 32 }) 33 }) 34 35 b.Run("Map_timeConsuming", func(b *testing.B) { 36 b.RunParallel(func(p *testing.PB) { 37 for p.Next() { 38 zarray.Map(l2, func(i int, v int) string { 39 time.Sleep(time.Microsecond) 40 return ztype.ToString(v) + "//" 41 }) 42 } 43 }) 44 }) 45 46 b.Run("ParallelMap_timeConsuming", func(b *testing.B) { 47 b.RunParallel(func(p *testing.PB) { 48 for p.Next() { 49 zarray.ParallelMap(l2, func(i int, v int) string { 50 time.Sleep(time.Microsecond) 51 return ztype.ToString(v) + "//" 52 }, uint(len(l2))) 53 } 54 }) 55 }) 56 57 }