github.com/ipld/go-ipld-prime@v0.21.0/storage/tests/generators.go (about)

     1  package tests
     2  
     3  import (
     4  	"strconv"
     5  )
     6  
     7  // Gen is a func which should generate key-value pairs.
     8  // It's used to configure benchmarks.
     9  //
    10  // How exactly to use this is up to you, but
    11  // a good gen function should probably return a wide variety of keys,
    12  // and some known distribution of key and content sizes.
    13  // If it returns the same key frequently, it should be documented,
    14  // because key collision rates will affect benchmark results.
    15  type Gen func() (key string, content []byte)
    16  
    17  // NewCounterGen returns a Gen func which yields a unique value on each subsequent call,
    18  // which is simply the base-10 string representation of an incrementing integer.
    19  // The content and the key are the same.
    20  func NewCounterGen(start int64) Gen {
    21  	return func() (key string, content []byte) {
    22  		k := strconv.FormatInt(start, 10)
    23  		start++
    24  		return k, []byte(k)
    25  	}
    26  }