bench

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bench implements concurrent benchmark for cache backends.

Index

Constants

View Source
const (
	LongString = "looooooooooooooooooooooooooongstring"
	KeyPrefix  = "thekey"
)

Sample values.

Variables

View Source
var (
	Failovers = []Runner{
		FailoverRunner{F: func() cache.ReadWriter {
			return cache.NewShardedMap()
		}},
		FailoverRunner{F: func() cache.ReadWriter {
			return cache.NewSyncMap()
		}},
	}

	Baseline = []Runner{
		SyncMapBaseline{},
		ShardedMapBaseline{},
		&MutexMap{},
		&RWMutexMap{},
	}

	ReadWriters = []Runner{
		ReadWriterRunner{Name: "ShardedMap/LRU", F: func() cache.ReadWriter {
			return cache.NewShardedMap(func(cfg *cache.Config) {
				cfg.CountSoftLimit = 1e10
				cfg.EvictionStrategy = cache.EvictLeastRecentlyUsed
			})
		}},
		ReadWriterRunner{F: func() cache.ReadWriter {
			return cache.NewShardedMap()
		}},
		ReadWriterRunner{F: func() cache.ReadWriter {
			return cache.NewSyncMap()
		}},
	}
)

Default runners.

Functions

func Concurrently

func Concurrently(b *testing.B, scenarios []Scenario)

Concurrently runs benchmarks concurrently.

func StableHeapInUse

func StableHeapInUse() int64

StableHeapInUse attempts to determine heap in use when new allocations are reduced.

Types

type FailoverOf

type FailoverOf struct {
	F func() cache.ReadWriterOf[SmallCachedValue]

	C           *cache.FailoverOf[SmallCachedValue]
	D           cache.Deleter
	Cardinality int
}

FailoverOf is a benchmark runner.

func (FailoverOf) Make

func (cl FailoverOf) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (FailoverOf) Run

func (cl FailoverOf) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type FailoverRunner

type FailoverRunner struct {
	F func() cache.ReadWriter

	C           *cache.Failover
	D           cache.Deleter
	Cardinality int
}

FailoverRunner is a benchmark runner.

func (FailoverRunner) Make

func (r FailoverRunner) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (FailoverRunner) Run

func (r FailoverRunner) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type MutexMap

type MutexMap struct {
	// contains filtered or unexported fields
}

MutexMap is a benchmark runner.

func (*MutexMap) Make

func (r *MutexMap) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (*MutexMap) Run

func (r *MutexMap) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type RWMutexMap

type RWMutexMap struct {
	// contains filtered or unexported fields
}

RWMutexMap is a benchmark runner.

func (*RWMutexMap) Make

func (r *RWMutexMap) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (*RWMutexMap) Run

func (r *RWMutexMap) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type ReadWriterOfRunner

type ReadWriterOfRunner struct {
	F func() cache.ReadWriterOf[SmallCachedValue]

	RW          cache.ReadWriterOf[SmallCachedValue]
	D           cache.Deleter
	Cardinality int
	Name        string
}

ReadWriterOfRunner creates benchmark runner from cache.ReadWriterOf.

func (ReadWriterOfRunner) Make

func (cl ReadWriterOfRunner) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (ReadWriterOfRunner) Run

func (cl ReadWriterOfRunner) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type ReadWriterRunner

type ReadWriterRunner struct {
	F func() cache.ReadWriter

	RW          cache.ReadWriter
	D           cache.Deleter
	Cardinality int
	Name        string
}

ReadWriterRunner is a benchmark runner.

func (ReadWriterRunner) Make

func (cl ReadWriterRunner) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (ReadWriterRunner) Run

func (cl ReadWriterRunner) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type Runner

type Runner interface {
	Make(b *testing.B, cardinality int) (Runner, string)
	Run(b *testing.B, cnt int, writeEvery int)
}

Runner describes cache benchmark runner.

type Scenario

type Scenario struct {
	Cardinality  int
	NumRoutines  int
	WritePercent float64
	Runners      []Runner
}

Scenario describes benchmark scenario.

type ShardedMapBaseline

type ShardedMapBaseline struct {
	// contains filtered or unexported fields
}

ShardedMapBaseline is a benchmark runner.

func (ShardedMapBaseline) Make

func (cl ShardedMapBaseline) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (ShardedMapBaseline) Run

func (cl ShardedMapBaseline) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type ShardedMapOfBaseline

type ShardedMapOfBaseline struct {
	// contains filtered or unexported fields
}

ShardedMapOfBaseline is a benchmark runner.

func (ShardedMapOfBaseline) Make

func (cl ShardedMapOfBaseline) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (ShardedMapOfBaseline) Run

func (cl ShardedMapOfBaseline) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

type SmallCachedValue

type SmallCachedValue struct {
	B bool
	S string
	I int
}

SmallCachedValue represents a small value for a cached item.

func MakeCachedValue

func MakeCachedValue(i int) SmallCachedValue

MakeCachedValue creates a SmallCachedValue.

func (SmallCachedValue) MarshalBinary

func (s SmallCachedValue) MarshalBinary() (data []byte, err error)

MarshalBinary encodes SmallCachedValue to bytes.

func (*SmallCachedValue) UnmarshalBinary

func (s *SmallCachedValue) UnmarshalBinary(data []byte) error

UnmarshalBinary loads value from bytes.

type SyncMapBaseline

type SyncMapBaseline struct {
	// contains filtered or unexported fields
}

SyncMapBaseline is a benchmark runner.

func (SyncMapBaseline) Make

func (r SyncMapBaseline) Make(b *testing.B, cardinality int) (Runner, string)

Make initializes benchmark runner.

func (SyncMapBaseline) Run

func (r SyncMapBaseline) Run(b *testing.B, cnt int, writeEvery int)

Run iterates over the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL