Codebase list golang-github-renekroon-ttlcache / 4065cc93-4ee9-429e-a026-bcc4d0e3fe20/main bench / bench_test.go
4065cc93-4ee9-429e-a026-bcc4d0e3fe20/main

Tree @4065cc93-4ee9-429e-a026-bcc4d0e3fe20/main (Download .tar.gz)

bench_test.go @4065cc93-4ee9-429e-a026-bcc4d0e3fe20/mainraw · history · blame

package bench

import (
	"fmt"
	"testing"
	"time"

	ttlcache "github.com/ReneKroon/ttlcache/v2"
)

func BenchmarkCacheSetWithoutTTL(b *testing.B) {
	cache := ttlcache.NewCache()
	defer cache.Close()

	for n := 0; n < b.N; n++ {
		cache.Set(fmt.Sprint(n%1000000), "value")
	}
}

func BenchmarkCacheSetWithGlobalTTL(b *testing.B) {
	cache := ttlcache.NewCache()
	defer cache.Close()

	cache.SetTTL(time.Duration(50 * time.Millisecond))
	for n := 0; n < b.N; n++ {
		cache.Set(fmt.Sprint(n%1000000), "value")
	}
}

func BenchmarkCacheSetWithTTL(b *testing.B) {
	cache := ttlcache.NewCache()
	defer cache.Close()

	for n := 0; n < b.N; n++ {
		cache.SetWithTTL(fmt.Sprint(n%1000000), "value", time.Duration(50*time.Millisecond))
	}
}