pgregory.net/rand@v1.0.3-0.20230808192358-a0b8ce02f4da/rand_bench_fast_test.go (about) 1 // Copyright 2022 Gregory Petrosyan <gregory.petrosyan@gmail.com> 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, v. 2.0. If a copy of the MPL was not distributed with this 5 // file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 7 //go:build benchfast 8 9 package rand_test 10 11 import ( 12 "github.com/valyala/fastrand" 13 "testing" 14 ) 15 16 func BenchmarkUint64(b *testing.B) { 17 b.RunParallel(func(pb *testing.PB) { 18 var s uint64 19 for pb.Next() { 20 s = uint64(fastrand.Uint32())<<32 | uint64(fastrand.Uint32()) 21 } 22 sinkUint64 = s 23 }) 24 } 25 26 func BenchmarkIntn(b *testing.B) { 27 b.RunParallel(func(pb *testing.PB) { 28 var s uint32 29 for pb.Next() { 30 s = fastrand.Uint32n(small) 31 } 32 sinkUint32 = s 33 }) 34 }