gf/util/grand/grand_z_bench_test.go

70 lines
1.2 KiB
Go
Raw Normal View History

// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// go test *.go -bench=".*"
package grand_test
import (
"crypto/rand"
"encoding/binary"
2019-06-19 09:06:52 +08:00
"testing"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/util/grand"
)
2018-11-23 21:39:05 +08:00
var buffer = make([]byte, 8)
2020-03-30 20:31:47 +08:00
func Benchmark_Rand_Intn(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.N(0, 99)
}
}
2020-03-30 20:31:47 +08:00
func Benchmark_Perm10(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.Perm(10)
}
}
func Benchmark_Perm100(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.Perm(100)
}
}
func Benchmark_Rand_N1(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.N(0, 99)
}
}
func Benchmark_Rand_N2(b *testing.B) {
2019-06-19 09:06:52 +08:00
for i := 0; i < b.N; i++ {
grand.N(0, 999999999)
2019-06-19 09:06:52 +08:00
}
}
2018-11-23 21:39:05 +08:00
func Benchmark_Str(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.S(16)
}
}
func Benchmark_StrSymbols(b *testing.B) {
for i := 0; i < b.N; i++ {
grand.S(16, true)
}
}
func Benchmark_Buffer(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := rand.Read(buffer); err == nil {
binary.LittleEndian.Uint64(buffer)
}
}
}