github.com/goark/mt@v0.4.0/benchmark/benchmark_test.go (about) 1 package benchmark 2 3 import ( 4 "math/rand" 5 "testing" 6 "time" 7 8 "github.com/goark/mt" 9 "github.com/goark/mt/mt19937" 10 ) 11 12 const count = 10000000 13 14 func BenchmarkRandomALFG(b *testing.B) { 15 rnd := rand.NewSource(time.Now().UnixNano()).(rand.Source64) 16 b.ResetTimer() 17 for i := 0; i < count; i++ { 18 rnd.Uint64() 19 } 20 } 21 22 func BenchmarkRandomMT19917(b *testing.B) { 23 rnd := mt19937.New(time.Now().UnixNano()) 24 b.ResetTimer() 25 for i := 0; i < count; i++ { 26 rnd.Uint64() 27 } 28 } 29 30 func BenchmarkRandomALFGRand(b *testing.B) { 31 rnd := rand.New(rand.NewSource(time.Now().UnixNano())) 32 b.ResetTimer() 33 for i := 0; i < count; i++ { 34 rnd.Uint64() 35 } 36 } 37 38 func BenchmarkRandomMT19917Rand(b *testing.B) { 39 rnd := rand.New(mt19937.New(time.Now().UnixNano())) 40 b.ResetTimer() 41 for i := 0; i < count; i++ { 42 rnd.Uint64() 43 } 44 } 45 46 func BenchmarkRandomALFGLocked(b *testing.B) { 47 b.ResetTimer() 48 for i := 0; i < count; i++ { 49 rand.Uint64() 50 } 51 } 52 53 func BenchmarkRandomMT19917Locked(b *testing.B) { 54 rnd := mt.New(mt19937.New(time.Now().UnixNano())) 55 b.ResetTimer() 56 for i := 0; i < count; i++ { 57 rnd.Uint64() 58 } 59 } 60 61 /* MIT License 62 * 63 * Copyright 2019 Spiegel 64 * 65 * Permission is hereby granted, free of charge, to any person obtaining a copy 66 * of this software and associated documentation files (the "Software"), to deal 67 * in the Software without restriction, including without limitation the rights 68 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 69 * copies of the Software, and to permit persons to whom the Software is 70 * furnished to do so, subject to the following conditions: 71 * 72 * The above copyright notice and this permission notice shall be included in all 73 * copies or substantial portions of the Software. 74 * 75 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 76 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 77 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 78 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 79 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 80 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 81 * SOFTWARE. 82 */