Skip to content

Commit

Permalink
Benchmark results.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Sep 5, 2019
1 parent cda7d8d commit 5e9a709
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,29 @@

This is free and unencumbered software released into the
[public domain](https://creativecommons.org/publicdomain/zero/1.0).


## Performance

Unix domain sockets provide a significant boost, when compared to TCP.
The following results were measured on a E5-1650 v2 (from the year 2013).

```
name old time/op new time/op delta
SimpleString/sequential-12 63.6µs ± 0% 34.4µs ± 1% -46.03% (p=0.000 n=16+16)
SimpleString/parallel-12 20.3µs ± 1% 6.1µs ± 3% -70.03% (p=0.000 n=15+16)
Integer/sequential-12 62.0µs ± 0% 33.2µs ± 0% -46.51% (p=0.000 n=15+16)
Integer/parallel-12 20.0µs ± 2% 5.9µs ± 2% -70.42% (p=0.000 n=16+14)
BulkString/1B/sequential-12 62.8µs ± 0% 33.7µs ± 0% -46.34% (p=0.000 n=16+16)
BulkString/1B/parallel-12 20.2µs ± 1% 6.0µs ± 1% -70.49% (p=0.000 n=14+15)
BulkString/144B/sequential-12 63.6µs ± 0% 34.6µs ± 0% -45.57% (p=0.000 n=16+14)
BulkString/144B/parallel-12 20.3µs ± 2% 6.1µs ± 2% -70.01% (p=0.000 n=16+16)
BulkString/20736B/sequential-12 80.0µs ± 1% 80.8µs ± 0% +1.04% (p=0.000 n=15+15)
BulkString/20736B/parallel-12 33.6µs ± 4% 54.5µs ± 0% +62.21% (p=0.000 n=14+13)
Array/1×8B/sequential-12 65.8µs ± 0% 36.1µs ± 0% -45.10% (p=0.000 n=13+14)
Array/1×8B/parallel-12 20.6µs ± 1% 6.5µs ± 4% -68.63% (p=0.000 n=16+16)
Array/12×8B/sequential-12 68.4µs ± 0% 38.8µs ± 0% -43.31% (p=0.000 n=13+15)
Array/12×8B/parallel-12 20.6µs ± 0% 7.4µs ± 5% -63.98% (p=0.000 n=13+15)
Array/144×8B/sequential-12 90.9µs ± 0% 60.9µs ± 0% -32.99% (p=0.000 n=16+16)
Array/144×8B/parallel-12 26.2µs ± 3% 23.7µs ± 2% -9.27% (p=0.000 n=14+16)
```
43 changes: 31 additions & 12 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ func TestFirstByteError(t *testing.T) {
}

func BenchmarkSimpleString(b *testing.B) {
const key = "bench-key"
key := randomKey("bench")
defer func() {
if _, err := benchClient.DEL(key); err != nil {
b.Error("cleanup error:", err)
}
}()

value := make([]byte, 8)
b.Run("sequential", func(b *testing.B) {
for i := 0; i < b.N; i++ {
Expand All @@ -208,7 +214,8 @@ func BenchmarkSimpleString(b *testing.B) {
}

func BenchmarkInteger(b *testing.B) {
const key = "bench-key"
key := randomKey("bench")

b.Run("sequential", func(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := benchClient.DEL(key); err != nil {
Expand All @@ -228,9 +235,15 @@ func BenchmarkInteger(b *testing.B) {
}

func BenchmarkBulkString(b *testing.B) {
const key = "bench-key"
for _, size := range []int{8, 200, 1000} {
b.Run(fmt.Sprintf("%dbyte", size), func(b *testing.B) {
key := randomKey("bench")
defer func() {
if _, err := benchClient.DEL(key); err != nil {
b.Error("cleanup error:", err)
}
}()

for _, size := range []int{1, 144, 20_736} {
b.Run(fmt.Sprintf("%dB", size), func(b *testing.B) {
if err := benchClient.SET(key, make([]byte, size)); err != nil {
b.Fatal("population error:", err)
}
Expand Down Expand Up @@ -264,27 +277,32 @@ func BenchmarkBulkString(b *testing.B) {
}

func BenchmarkArray(b *testing.B) {
const key = "bench-array"
key := randomKey("bench")
defer func() {
if _, err := benchClient.DEL(key); err != nil {
b.Fatal("cleanup error:", err)
b.Error("cleanup error:", err)
}
}()

for _, size := range []int64{2, 12, 144} {
b.Run(fmt.Sprintf("%dvalues", size), func(b *testing.B) {
for n, err := benchClient.LLEN(key); n < size; n, err = benchClient.RPUSHString(key, "some-value") {
for _, size := range []int64{1, 12, 144} {
b.Run(fmt.Sprintf("%d×8B", size), func(b *testing.B) {
for {
n, err := benchClient.RPUSH(key, make([]byte, 8))
if err != nil {
b.Fatal("population error:", err)
}
if n >= size {
break
}
}

b.Run("sequential", func(b *testing.B) {
for i := 0; i < b.N; i++ {
values, err := benchClient.LRANGE(key, 0, size-1)
if err != nil {
b.Fatal("error:", err)
} else if int64(len(values)) != size {
}
if int64(len(values)) != size {
b.Fatalf("got %d values", len(values))
}
}
Expand All @@ -295,7 +313,8 @@ func BenchmarkArray(b *testing.B) {
values, err := benchClient.LRANGE(key, 0, size-1)
if err != nil {
b.Fatal("error:", err)
} else if int64(len(values)) != size {
}
if int64(len(values)) != size {
b.Fatalf("got %d values", len(values))
}
}
Expand Down

0 comments on commit 5e9a709

Please sign in to comment.