Skip to content

Commit

Permalink
add benchmarks for all storages
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Sep 14, 2023
1 parent f8afad5 commit 68d5928
Show file tree
Hide file tree
Showing 20 changed files with 864 additions and 17 deletions.
62 changes: 51 additions & 11 deletions arangodb/arangodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var testStore = New(Config{
Reset: true,
})

func Test_ARANGODB_Set(t *testing.T) {
func Test_ArangoDB_Set(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -21,7 +21,7 @@ func Test_ARANGODB_Set(t *testing.T) {
require.NoError(t, err)
}

func Test_ARANGODB_Upsert(t *testing.T) {
func Test_ArangoDB_Upsert(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -34,7 +34,7 @@ func Test_ARANGODB_Upsert(t *testing.T) {
require.NoError(t, err)
}

func Test_ARANGODB_Get(t *testing.T) {
func Test_ArangoDB_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -48,7 +48,7 @@ func Test_ARANGODB_Get(t *testing.T) {
require.Equal(t, val, result)
}

func Test_ARANGODB_Set_Expiration(t *testing.T) {
func Test_ArangoDB_Set_Expiration(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -61,21 +61,21 @@ func Test_ARANGODB_Set_Expiration(t *testing.T) {
time.Sleep(1100 * time.Millisecond)
}

func Test_ARANGODB_Get_Expired(t *testing.T) {
func Test_ArangoDB_Get_Expired(t *testing.T) {
key := "john"

result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Get_NotExist(t *testing.T) {
func Test_ArangoDB_Get_NotExist(t *testing.T) {
result, err := testStore.Get("notexist")
require.NoError(t, err)
require.Zero(t, len(result))
}

func Test_ARANGODB_Delete(t *testing.T) {
func Test_ArangoDB_Delete(t *testing.T) {
var (
key = "john"
val = []byte("doe")
Expand All @@ -92,7 +92,7 @@ func Test_ARANGODB_Delete(t *testing.T) {
require.Zero(t, len(result))
}

func Test_ARANGODB_Reset(t *testing.T) {
func Test_ArangoDB_Reset(t *testing.T) {
val := []byte("doe")

err := testStore.Set("john1", val, 0)
Expand All @@ -113,7 +113,7 @@ func Test_ARANGODB_Reset(t *testing.T) {
require.Zero(t, len(result))
}

func Test_ARANGODB_Non_UTF8(t *testing.T) {
func Test_ArangoDB_Non_UTF8(t *testing.T) {
val := []byte("0xF5")

err := testStore.Set("0xF6", val, 0)
Expand All @@ -124,10 +124,50 @@ func Test_ARANGODB_Non_UTF8(t *testing.T) {
require.Equal(t, val, result)
}

func Test_ARANGODB_Close(t *testing.T) {
func Test_ArangoDB_Close(t *testing.T) {
require.Nil(t, testStore.Close())
}

func Test_ARANGODB_Conn(t *testing.T) {
func Test_ArangoDB_Conn(t *testing.T) {
require.True(t, testStore.Conn() != nil)
}

func Benchmark_ArangoDB_Set(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

require.NoError(b, err)
}

func Benchmark_ArangoDB_Get(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

require.NoError(b, err)
}

func Benchmark_ArangoDB_Delete(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = testStore.Delete("john")
}

require.NoError(b, err)
}
44 changes: 44 additions & 0 deletions azureblob/azureblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,47 @@ func Test_AzureBlob_Close(t *testing.T) {
testStore := newStore()
require.Nil(t, testStore.Close())
}

func Benchmark_AzureBlob_Set(b *testing.B) {
testStore := newStore()

b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

require.NoError(b, err)
}

func Benchmark_AzureBlob_Get(b *testing.B) {
testStore := newStore()
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

require.NoError(b, err)
}

func Benchmark_AzureBlob_Delete(b *testing.B) {
testStore := newStore()
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = testStore.Delete("john")
}

require.NoError(b, err)
}
40 changes: 40 additions & 0 deletions badger/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,43 @@ func Test_Badger_Close(t *testing.T) {
func Test_Badger_Conn(t *testing.T) {
require.True(t, testStore.Conn() != nil)
}

func Benchmark_Badger_Set(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

require.NoError(b, err)
}

func Benchmark_Badger_Get(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

require.NoError(b, err)
}

func Benchmark_Badger_Delete(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = testStore.Delete("john")
}

require.NoError(b, err)
}
40 changes: 40 additions & 0 deletions bbolt/bbolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,43 @@ func Test_Bbolt_Close(t *testing.T) {
func Test_Bbolt_Conn(t *testing.T) {
require.True(t, testStore.Conn() != nil)
}

func Benchmark_Bbolt_Set(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

require.NoError(b, err)
}

func Benchmark_Bbolt_Get(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

require.NoError(b, err)
}

func Benchmark_Bbolt_Delete(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = testStore.Delete("john")
}

require.NoError(b, err)
}
62 changes: 56 additions & 6 deletions coherence/coherence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ var (
value2 = []byte("value2")
)

// newTestStore returns a new Coherence Store and ensures it is reset.
func newTestStore(t testing.TB, config ...Config) (*Storage, error) {
t.Helper()

testStore, err := New(config...)
utils.AssertEqual(t, err, nil)

err = testStore.Reset()

return testStore, err
}

func Test_Coherence_Set_And_Get(t *testing.T) {
var val []byte

Expand Down Expand Up @@ -196,12 +208,50 @@ func Test_Coherence_With_Scope(t *testing.T) {
utils.AssertEqual(t, testStore2.Close(), nil)
}

// newTestStore returns a new Coherence Store and ensures it is reset.
func newTestStore(t *testing.T, config ...Config) (*Storage, error) {
testStore, err := New(config...)
utils.AssertEqual(t, err, nil)
func Benchmark_Coherence_Set(b *testing.B) {
testStore, err := newTestStore(b)
utils.AssertEqual(b, nil, err)

err = testStore.Reset()
b.ReportAllocs()
b.ResetTimer()

return testStore, err
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}

utils.AssertEqual(b, nil, err)
}

func Benchmark_Coherence_Get(b *testing.B) {
testStore, err := newTestStore(b)
utils.AssertEqual(b, nil, err)

err = testStore.Set("john", []byte("doe"), 0)
utils.AssertEqual(b, nil, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}

utils.AssertEqual(b, nil, err)
}

func Benchmark_Coherence_Delete(b *testing.B) {
testStore, err := newTestStore(b)
utils.AssertEqual(b, nil, err)

err = testStore.Set("john", []byte("doe"), 0)
utils.AssertEqual(b, nil, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = testStore.Delete("john")
}

utils.AssertEqual(b, nil, err)
}
Loading

0 comments on commit 68d5928

Please sign in to comment.