github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/internal/rawalloc/rawalloc_test.go (about)

     1  // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package rawalloc
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  var sizes = []int{16, 100, 1024, 1024 * 10, 1024 * 100, 1024 * 1024}
    13  
    14  func BenchmarkRawalloc(b *testing.B) {
    15  	for _, size := range sizes {
    16  		b.Run(fmt.Sprintf("rawalloc-%d", size), func(b *testing.B) {
    17  			for i := 0; i < b.N; i++ {
    18  				_ = New(size, size)
    19  			}
    20  		})
    21  	}
    22  }
    23  
    24  func BenchmarkMake(b *testing.B) {
    25  	for _, size := range sizes {
    26  		b.Run(fmt.Sprintf("make-%d", size), func(b *testing.B) {
    27  			for i := 0; i < b.N; i++ {
    28  				_ = make([]byte, size)
    29  			}
    30  		})
    31  	}
    32  }