...

Source file src/github.com/jellydator/ttlcache/v3/bench/bench_test.go

Documentation: github.com/jellydator/ttlcache/v3/bench

     1  package bench
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	ttlcache "github.com/jellydator/ttlcache/v3"
     9  )
    10  
    11  func BenchmarkCacheSetWithoutTTL(b *testing.B) {
    12  	cache := ttlcache.New[string, string]()
    13  
    14  	for n := 0; n < b.N; n++ {
    15  		cache.Set(fmt.Sprint(n%1000000), "value", ttlcache.NoTTL)
    16  	}
    17  }
    18  
    19  func BenchmarkCacheSetWithGlobalTTL(b *testing.B) {
    20  	cache := ttlcache.New[string, string](
    21  		ttlcache.WithTTL[string, string](50 * time.Millisecond),
    22  	)
    23  
    24  	for n := 0; n < b.N; n++ {
    25  		cache.Set(fmt.Sprint(n%1000000), "value", ttlcache.DefaultTTL)
    26  	}
    27  }
    28  

View as plain text