github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/soliton/collate/collate_bench_test.go (about)

     1  package defCauslate
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  
     7  	_ "net/http/pprof"
     8  )
     9  
    10  const short = 2 << 4
    11  const midbse = 2 << 10
    12  const long = 2 << 20
    13  
    14  func generateData(length int) string {
    15  	rs := []rune("ßss")
    16  	r := make([]rune, length)
    17  	for i := range r {
    18  		r[i] = rs[rand.Intn(len(rs))]
    19  	}
    20  
    21  	return string(r)
    22  }
    23  
    24  func compare(b *testing.B, defCauslator DefCauslator, length int) {
    25  	s1 := generateData(length)
    26  	s2 := generateData(length)
    27  
    28  	b.ResetTimer()
    29  	for i := 0; i < b.N; i++ {
    30  		if defCauslator.Compare(s1, s2) != 0 {
    31  		}
    32  	}
    33  }
    34  
    35  func key(b *testing.B, defCauslator DefCauslator, length int) {
    36  	s := generateData(length)
    37  
    38  	b.ResetTimer()
    39  	for i := 0; i < b.N; i++ {
    40  		defCauslator.Key(s)
    41  	}
    42  }
    43  
    44  func BenchmarkUtf8mb4Bin_CompareShort(b *testing.B) {
    45  	compare(b, &binDefCauslator{}, short)
    46  }
    47  
    48  func BenchmarkUtf8mb4GeneralCI_CompareShort(b *testing.B) {
    49  	compare(b, &generalCIDefCauslator{}, short)
    50  }
    51  
    52  func BenchmarkUtf8mb4UnicodeCI_CompareShort(b *testing.B) {
    53  	compare(b, &unicodeCIDefCauslator{}, short)
    54  }
    55  
    56  func BenchmarkUtf8mb4Bin_CompareMid(b *testing.B) {
    57  	compare(b, &binDefCauslator{}, midbse)
    58  }
    59  
    60  func BenchmarkUtf8mb4GeneralCI_CompareMid(b *testing.B) {
    61  	compare(b, &generalCIDefCauslator{}, midbse)
    62  }
    63  
    64  func BenchmarkUtf8mb4UnicodeCI_CompareMid(b *testing.B) {
    65  	compare(b, &unicodeCIDefCauslator{}, midbse)
    66  }
    67  
    68  func BenchmarkUtf8mb4Bin_CompareLong(b *testing.B) {
    69  	compare(b, &binDefCauslator{}, long)
    70  }
    71  
    72  func BenchmarkUtf8mb4GeneralCI_CompareLong(b *testing.B) {
    73  	compare(b, &generalCIDefCauslator{}, long)
    74  }
    75  
    76  func BenchmarkUtf8mb4UnicodeCI_CompareLong(b *testing.B) {
    77  	compare(b, &unicodeCIDefCauslator{}, long)
    78  }
    79  
    80  func BenchmarkUtf8mb4Bin_KeyShort(b *testing.B) {
    81  	key(b, &binDefCauslator{}, short)
    82  }
    83  
    84  func BenchmarkUtf8mb4GeneralCI_KeyShort(b *testing.B) {
    85  	key(b, &generalCIDefCauslator{}, short)
    86  }
    87  
    88  func BenchmarkUtf8mb4UnicodeCI_KeyShort(b *testing.B) {
    89  	key(b, &unicodeCIDefCauslator{}, short)
    90  }
    91  
    92  func BenchmarkUtf8mb4Bin_KeyMid(b *testing.B) {
    93  	key(b, &binDefCauslator{}, midbse)
    94  }
    95  
    96  func BenchmarkUtf8mb4GeneralCI_KeyMid(b *testing.B) {
    97  	key(b, &generalCIDefCauslator{}, midbse)
    98  }
    99  
   100  func BenchmarkUtf8mb4UnicodeCI_KeyMid(b *testing.B) {
   101  	key(b, &unicodeCIDefCauslator{}, midbse)
   102  }
   103  
   104  func BenchmarkUtf8mb4Bin_KeyLong(b *testing.B) {
   105  	key(b, &binDefCauslator{}, long)
   106  }
   107  
   108  func BenchmarkUtf8mb4GeneralCI_KeyLong(b *testing.B) {
   109  	key(b, &generalCIDefCauslator{}, long)
   110  }
   111  
   112  func BenchmarkUtf8mb4UnicodeCI_KeyLong(b *testing.B) {
   113  	key(b, &unicodeCIDefCauslator{}, long)
   114  }