github.com/GitbookIO/syncgroup@v0.0.0-20200915204659-4f0b2961ab10/quickhash/aeshash/aeshash_bench_test.go (about)

     1  package aeshash
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  const B = 1
     8  const K = 1024
     9  const M = K * K
    10  
    11  func BenchmarkAES_16B(b *testing.B) {
    12  	benchHash(b, 16)
    13  }
    14  func BenchmarkAES_32B(b *testing.B) {
    15  	benchHash(b, 32)
    16  }
    17  func BenchmarkAES_64B(b *testing.B) {
    18  	benchHash(b, 64)
    19  }
    20  func BenchmarkAES_128B(b *testing.B) {
    21  	benchHash(b, 128)
    22  }
    23  
    24  func BenchmarkAES_256B(b *testing.B) {
    25  	benchHash(b, 256)
    26  }
    27  
    28  func BenchmarkAES_512B(b *testing.B) {
    29  	benchHash(b, 512)
    30  }
    31  
    32  func BenchmarkAES_1KB(b *testing.B) {
    33  	benchHash(b, K)
    34  }
    35  func BenchmarkAES_4KB(b *testing.B) {
    36  	benchHash(b, 4*K)
    37  }
    38  
    39  func BenchmarkAES_16KB(b *testing.B) {
    40  	benchHash(b, 16*K)
    41  }
    42  
    43  func BenchmarkAES_128KB(b *testing.B) {
    44  	benchHash(b, 128*K)
    45  }
    46  
    47  func BenchmarkAES_256KB(b *testing.B) {
    48  	benchHash(b, 256*K)
    49  }
    50  
    51  func BenchmarkAES_512KB(b *testing.B) {
    52  	benchHash(b, 512*K)
    53  }
    54  func BenchmarkAES_1MB(b *testing.B) {
    55  	benchHash(b, 1*M)
    56  }
    57  
    58  func BenchmarkAES_2MB(b *testing.B) {
    59  	benchHash(b, 2*M)
    60  }
    61  
    62  func BenchmarkAES_4MB(b *testing.B) {
    63  	benchHash(b, 4*M)
    64  }
    65  
    66  func benchHash(b *testing.B, bufferSize int64) {
    67  	buffer := make([]byte, bufferSize)
    68  	b.SetBytes(bufferSize)
    69  	for n := 0; n < b.N; n++ {
    70  		Hash(buffer, 42)
    71  	}
    72  }