Created
July 10, 2012 23:53
-
-
Save auxesis/3087023 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'redis' | |
| require 'json' | |
| require 'msgpack' | |
| require 'benchmark' | |
| # mock event | |
| event = { | |
| 'host' => 'app-01', | |
| 'service' => 'http', | |
| 'type' => 'service', | |
| 'state' => 'critical', | |
| } | |
| redis = Redis.new | |
| redis.ltrim('bm_events', 0, 0) # reset the list | |
| # number of iterations | |
| i = 100_000 | |
| 5.times do | |
| Benchmark.bm(14) do |x| | |
| x.report("json encode") do | |
| i.times { redis.rpush 'bm_events', event.to_json } | |
| end | |
| x.report("json decode") do | |
| i.times { JSON.parse(redis.blpop('bm_events').last) } | |
| end | |
| x.report("msgpack encode") do | |
| i.times { redis.rpush 'bm_events', event.to_msgpack } | |
| end | |
| x.report("msgpack decode") do | |
| i.times { | |
| MessagePack.unpack(redis.blpop('bm_events').last) | |
| } | |
| end | |
| end | |
| puts | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user system total real | |
| json encode 8.190000 2.180000 10.370000 ( 19.493059) | |
| json decode 12.010000 2.260000 14.270000 ( 23.440085) | |
| msgpack encode 6.430000 2.080000 8.510000 ( 16.520134) | |
| msgpack decode 9.410000 2.250000 11.660000 ( 23.494708) | |
| user system total real | |
| json encode 7.820000 2.210000 10.030000 ( 23.738877) | |
| json decode 10.730000 2.350000 13.080000 ( 22.935052) | |
| msgpack encode 6.040000 2.080000 8.120000 ( 15.902375) | |
| msgpack decode 9.380000 2.230000 11.610000 ( 21.427978) | |
| user system total real | |
| json encode 7.910000 2.190000 10.100000 ( 18.816562) | |
| json decode 10.390000 2.310000 12.700000 ( 21.777471) | |
| msgpack encode 6.290000 2.140000 8.430000 ( 15.964847) | |
| msgpack decode 9.260000 2.220000 11.480000 ( 23.721213) | |
| user system total real | |
| json encode 7.660000 2.150000 9.810000 ( 19.705456) | |
| json decode 10.940000 2.400000 13.340000 ( 24.731049) | |
| msgpack encode 6.180000 2.120000 8.300000 ( 16.808059) | |
| msgpack decode 9.210000 2.190000 11.400000 ( 20.932655) | |
| user system total real | |
| json encode 7.660000 2.150000 9.810000 ( 18.501270) | |
| json decode 10.440000 2.310000 12.750000 ( 23.546371) | |
| msgpack encode 6.270000 2.140000 8.410000 ( 16.736538) | |
| msgpack decode 9.380000 2.210000 11.590000 ( 21.135084) |
Author
Yeah, it would be, but I just wanted to benchmark what was in the Ruby stdlib vs an outside library.
There's not enough of a speed improvement to warrant pulling in an external dependency.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yajl might be faster https://github.com/brianmario/yajl-ruby/