github.com/niubaoshu/goutils@v0.0.0-20180828035119-e8e576f66c2b/rand/mRandN_test.go (about)

     1  package rand
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/niubaoshu/goutils"
     9  )
    10  
    11  func TestMRandN(t *testing.T) {
    12  	for i := 0; i < 10; i++ {
    13  		rst := Perm(i, nil)
    14  		if goutils.CheckRepeat(rst) {
    15  			t.Error(rst)
    16  		}
    17  	}
    18  }
    19  
    20  func BenchmarkMSelectN(b *testing.B) {
    21  	r := NewMrandNWithLen(100000)
    22  	for i := 0; i < b.N; i++ {
    23  		r.SelectN(i, nil)
    24  	}
    25  }
    26  
    27  func BenchmarkPerm(b *testing.B) {
    28  	buf := make([]int, 0, 100000)
    29  	r := NewMrandNWithLen(100000)
    30  	for i := 0; i < b.N; i++ {
    31  		r.Perm(buf)
    32  	}
    33  }
    34  
    35  func BenchmarkMathRand(b *testing.B) {
    36  	r := rand.New(rand.NewSource(time.Now().UnixNano()))
    37  	for i := 0; i < b.N; i++ {
    38  		r.Perm(100000)
    39  	}
    40  }