For fun I'm writing a MessagePack encoder/decoder in pure Ruby to see how close to the speed of the native C and Java implementations I can get. Currently it's just 20% slower than the native C extension for decoding (haven't implemented encoding yet), and twice as slow as native Java, when running in the latest Java 1.7.
Below are some benchmarks run in both MRI and JRuby, comparing the native decoders for both platforms with my pure Ruby implementation with and without InvokeDynamic in JRuby.
The MessagePack decoder code is here: https://github.com/iconara/msgpack-pure-ruby/blob/647bcf74f8b059e5e31cc620f81eeb39b73393a4/lib/msgpack.rb
The benchmark code is here: https://github.com/iconara/msgpack-pure-ruby/blob/647bcf74f8b059e5e31cc620f81eeb39b73393a4/spec/benchmark.rb
The benchmark outputs start with the output of java -version
and then runs a series of benchmarks with one million repetitions of decoding the same chunk of bytes. The lines beginning with *
show the Ruby version used and additional info.
All of the tests were run in OS X 10.8.4.