github.com/koykov/openrt@v0.0.0-20240411200908-3abd933415e1/memclr_test.go (about)

     1  package openrt
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"testing"
     7  )
     8  
     9  var memclrStages [][]byte
    10  
    11  func init() {
    12  	for i := 0; i < 20; i++ {
    13  		l := 1 << i
    14  		stg := make([]byte, l)
    15  		for j := 0; j < len(stg); j++ {
    16  			stg[j] = 1
    17  		}
    18  		memclrStages = append(memclrStages, stg)
    19  	}
    20  }
    21  
    22  func TestMemclr(t *testing.T) {
    23  	for i := 0; i < len(memclrStages); i++ {
    24  		stg := memclrStages[i]
    25  		t.Run(strconv.Itoa(len(stg)), func(t *testing.T) {
    26  			Memclr(stg)
    27  		})
    28  	}
    29  }
    30  
    31  func BenchmarkMemclr(b *testing.B) {
    32  	for i := 0; i < len(memclrStages); i++ {
    33  		stg := memclrStages[i]
    34  		b.Run(fmt.Sprintf("runtime/%d", len(stg)), func(b *testing.B) {
    35  			b.ReportAllocs()
    36  			for j := 0; j < b.N; j++ {
    37  				Memclr(stg)
    38  			}
    39  		})
    40  	}
    41  }