Skip to content

Commit

Permalink
Record Ruby VS Hiredis benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Mar 22, 2024
1 parent 925bb6f commit 9fabd57
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Rakefile
Expand Up @@ -71,12 +71,15 @@ namespace :hiredis do
end
end

benchmark_suites = %w(single pipelined)
benchmark_suites = %w(single pipelined drivers)
benchmark_modes = %i[ruby yjit hiredis]
namespace :benchmark do
benchmark_suites.each do |suite|
benchmark_modes.each do |mode|
next if suite == "drivers" && mode == :hiredis

name = "#{suite}_#{mode}"
desc name
task name do
output_path = "benchmark/#{name}.md"
sh "rm", "-f", output_path
Expand Down
43 changes: 43 additions & 0 deletions benchmark/drivers.rb
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require_relative "setup"

ruby = RedisClient.new(host: "localhost", port: Servers::REDIS.real_port, driver: :ruby)
hiredis = RedisClient.new(host: "localhost", port: Servers::REDIS.real_port, driver: :hiredis)

ruby.call("SET", "key", "value")
ruby.call("SET", "large", "value" * 10_000)
ruby.call("LPUSH", "list", *5.times.to_a)
ruby.call("LPUSH", "large-list", *1000.times.to_a)
ruby.call("HMSET", "hash", *8.times.to_a)
ruby.call("HMSET", "large-hash", *1000.times.to_a)

benchmark("small string x 100") do |x|
x.report("hiredis") { hiredis.pipelined { |p| 100.times { p.call("GET", "key") } } }
x.report("ruby") { ruby.pipelined { |p| 100.times { p.call("GET", "key") } } }
end

benchmark("large string x 100") do |x|
x.report("hiredis") { hiredis.pipelined { |p| 100.times { p.call("GET", "large") } } }
x.report("ruby") { ruby.pipelined { |p| 100.times { p.call("GET", "large") } } }
end

benchmark("small list x 100") do |x|
x.report("hiredis") { hiredis.pipelined { |p| 100.times { p.call("LRANGE", "list", 0, -1) } } }
x.report("ruby") { ruby.pipelined { |p| 100.times { p.call("LRANGE", "list", 0, -1) } } }
end

benchmark("large list") do |x|
x.report("hiredis") { hiredis.call("LRANGE", "large-list", 0, -1) }
x.report("ruby") { ruby.call("LRANGE", "large-list", 0, -1) }
end

benchmark("small hash x 100") do |x|
x.report("hiredis") { hiredis.pipelined { |p| 100.times { p.call("HGETALL", "hash") } } }
x.report("ruby") { ruby.pipelined { |p| 100.times { p.call("HGETALL", "hash") } } }
end

benchmark("large hash") do |x|
x.report("hiredis") { ruby.call("HGETALL", "large-hash") }
x.report("ruby") { ruby.call("HGETALL", "large-hash") }
end
59 changes: 59 additions & 0 deletions benchmark/drivers_ruby.md
@@ -0,0 +1,59 @@
ruby: `ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]`

redis-server: `Redis server v=7.0.12 sha=00000000:0 malloc=libc bits=64 build=a11d0151eabf466c`


### small string x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 5402.4 i/s
ruby: 2877.9 i/s - 1.88x slower
```

### large string x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 297.2 i/s
ruby: 291.2 i/s - same-ish: difference falls within error
```

### small list x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 2632.0 i/s
ruby: 1136.1 i/s - 2.32x slower
```

### large list

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 6640.8 i/s
ruby: 1293.1 i/s - 5.14x slower
```

### small hash x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 3419.6 i/s
ruby: 1129.0 i/s - 3.03x slower
```

### large hash

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
hiredis: 1299.3 i/s
ruby: 1275.3 i/s - same-ish: difference falls within error
```

59 changes: 59 additions & 0 deletions benchmark/drivers_yjit.md
@@ -0,0 +1,59 @@
ruby: `ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]`

redis-server: `Redis server v=7.0.12 sha=00000000:0 malloc=libc bits=64 build=a11d0151eabf466c`


### small string x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 6745.7 i/s
ruby: 5182.0 i/s - 1.30x slower
```

### large string x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 303.5 i/s
ruby: 343.1 i/s - 1.13x faster
```

### small list x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 3683.6 i/s
ruby: 1952.3 i/s - 1.89x slower
```

### large list

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 6540.2 i/s
ruby: 2710.0 i/s - 2.41x slower
```

### small hash x 100

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 4002.6 i/s
ruby: 2317.0 i/s - 1.73x slower
```

### large hash

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [arm64-darwin23]
hiredis: 2467.1 i/s
ruby: 2439.0 i/s - same-ish: difference falls within error
```

0 comments on commit 9fabd57

Please sign in to comment.