From 2d67d31f902b2e3a8032c179ce957ab61635d898 Mon Sep 17 00:00:00 2001 From: John Guo Date: Wed, 13 Jan 2021 23:38:10 +0800 Subject: [PATCH] improve benckmark for package grand --- util/grand/grand_z_bench_test.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/util/grand/grand_z_bench_test.go b/util/grand/grand_z_bench_test.go index fc3a165ca..dc2361c28 100644 --- a/util/grand/grand_z_bench_test.go +++ b/util/grand/grand_z_bench_test.go @@ -9,11 +9,12 @@ package grand_test import ( - "crypto/rand" - "encoding/binary" - "testing" + cryptoRand "crypto/rand" + mathRand "math/rand" + "encoding/binary" "github.com/gogf/gf/util/grand" + "testing" ) var ( @@ -23,15 +24,21 @@ var ( strForStr = "我爱GoFrame" ) -func Benchmark_Rand_Buffer4(b *testing.B) { +func Benchmark_Math_Rand_Int(b *testing.B) { for i := 0; i < b.N; i++ { - rand.Read(randBuffer4) + mathRand.Int() } } -func Benchmark_Rand_Buffer1024(b *testing.B) { +func Benchmark_CryptoRand_Buffer4(b *testing.B) { for i := 0; i < b.N; i++ { - rand.Read(randBuffer1024) + cryptoRand.Read(randBuffer4) + } +} + +func Benchmark_CryptoRand_Buffer1024(b *testing.B) { + for i := 0; i < b.N; i++ { + cryptoRand.Read(randBuffer1024) } } @@ -101,9 +108,9 @@ func Benchmark_Uint32Converting(b *testing.B) { } } -func Benchmark_Buffer(b *testing.B) { +func Benchmark_CryptoRand_Buffer(b *testing.B) { for i := 0; i < b.N; i++ { - if _, err := rand.Read(buffer); err == nil { + if _, err := cryptoRand.Read(buffer); err == nil { binary.LittleEndian.Uint64(buffer) } }