Let's start with a fresh IRB session, load the json gem (which is implemented in C) and run a base benchmark.
[0] % irb 1.9.3p332 :001 > require 'json' => true 1.9.3p332 :002 > require 'benchmark' => true 1.9.3p332 :003 > Benchmark.measure { 500000.times { {'a' => 1, 'b' => [1, 2, '3']}.to_json } } => 8.730000 0.020000 8.750000 ( 8.757620) 1.9.3p332 :004 > Benchmark.measure { 500000.times { {'a' => 1, 'b' => [1, 2, '3']}.to_json } } => 8.310000 0.010000 8.320000 ( 8.332591)
Takes about 8 seconds to generate a small JSON 5 million times. Now let's look at what happens when we load active_support/json/encoding
1.9.3p332 :005 > require 'active_support/json/encoding' => true 1.9.3p332 :006 > Benchmark.measure { 500000.times { {'a' => 1, 'b' => [1, 2, '3']}.to_json } } => 101.110000 0.200000 101.310000 (101.445942) 1.9.3p332 :007 > Benchmark.measure { 500000.times { {'a' => 1, 'b' => [1, 2, '3']}.to_json } } => 98.440000 0.180000 98.620000 ( 98.738134)
That's right. It took about 100 seconds to do the same thing. My mind boggles. It's worse than even the pure-Ruby JSON gem, which takes about 30 seconds
[0] % irb 1.9.3p332 :004 > require 'json/pure' => true 1.9.3p332 :005 > require 'benchmark' => true 1.9.3p332 :006 > Benchmark.measure { 500000.times { {'a' => 1, 'b' => [1, 2, '3']}.to_json } } => 32.580000 0.060000 32.640000 ( 32.666449)