github.com/linuxboot/fiano@v1.2.0/pkg/bytes/is_zero_filled_test.go (about)

     1  // Copyright 2019 the LinuxBoot Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bytes
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func BenchmarkIsZeroFilled(b *testing.B) {
    13  	for _, size := range []uint64{0, 1, 256, 65536, 1 << 20} {
    14  		d := make([]byte, size)
    15  		b.Run(fmt.Sprintf("size_%d", size), func(b *testing.B) {
    16  			b.Run("default", func(b *testing.B) {
    17  				b.ReportAllocs()
    18  				b.ResetTimer()
    19  				for i := 0; i < b.N; i++ {
    20  					IsZeroFilled(d)
    21  				}
    22  			})
    23  			b.Run("simple", func(b *testing.B) {
    24  				b.ReportAllocs()
    25  				b.ResetTimer()
    26  				for i := 0; i < b.N; i++ {
    27  					isZeroFilledSimple(d)
    28  				}
    29  			})
    30  		})
    31  	}
    32  }