github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xstrings/random_test.go (about)

     1  package xstrings
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // BenchmarkRandom/random-12         	  188780	      5898 ns/op	    1720 B/op	      99 allocs/op
     8  // BenchmarkRandom/fast-12           	 3107966	       389 ns/op	     176 B/op	       4 allocs/op
     9  func BenchmarkRandom(b *testing.B) {
    10  	b.Run("random", func(b *testing.B) {
    11  		b.ResetTimer()
    12  		b.ReportAllocs()
    13  		for i := 0; i < b.N; i++ {
    14  			Random(RandomSet, 32)
    15  		}
    16  	})
    17  	b.Run("fast", func(b *testing.B) {
    18  		b.ResetTimer()
    19  		b.ReportAllocs()
    20  		for i := 0; i < b.N; i++ {
    21  			FastRandom(32)
    22  		}
    23  	})
    24  }