README.rdoc in brianmario-yajl-ruby-0.5.4 vs README.rdoc in brianmario-yajl-ruby-0.5.5
- old
+ new
@@ -2,10 +2,23 @@
This gem (although not in gem form just yet) is a C binding to the excellent YAJL JSON parsing and generation library.
You can read more info at the projects website http://lloydforge.org/projects/yajl or check out it's codes at http://github.com/lloyd/yajl.
+== Features
+
+* JSON parsing and encoding directly to and from an IO stream (file, socket, etc) or String. Compressed stream parsing and encoding supported for Bzip2, Gzip and Deflate.
+* Parse and encode *multiple* JSON objects to and from streams or strings continuously.
+* JSON gem compatibility API - allows yajl-ruby to be used as a drop-in replacement for the JSON gem
+* Basic HTTP client (only GET requests supported for now) which parses JSON directly off the response body *as it's being received*
+* ~3.5x faster than JSON.generate
+* ~1.9x faster than JSON.parse
+* ~4.5x faster than YAML.load
+* ~377.5x faster than YAML.dump
+* ~1.5x faster than Marshal.load
+* ~2x faster than Marshal.dump
+
== How to install
Install it like any other gem hosted at the Githubs like so:
(more instructions here: http://gems.github.com)
@@ -112,11 +125,11 @@
This allows you to encode JSON as a stream, writing directly to a socket
socket = TCPSocket.new(192.168.1.101, 9000)
hash = {:foo => 12425125, :bar => "some string", ... }
encoder = Yajl::Encoder.new
- Yajl::encoder.encode(hash, socket)
+ Yajl::Encoder.encode(hash, socket)
Or what if you wanted to compress the stream over the wire?
require 'yajl/gzip'
socket = TCPSocket.new(192.168.1.101, 9000)
@@ -133,12 +146,29 @@
encoder.encode(hash, socket)
end
You can also use Yajl::Bzip2::StreamWriter and Yajl::Deflate::StreamWriter. So you can pick whichever fits your CPU/bandwidth sweet-spot.
-There are a lot more possibilities, some of which I'm going to write other gems/plugins for.
+== JSON gem Compatibility API
+The JSON gem compatibility API isn't enabled by default. You have to explicitly require it like so:
+
+ require 'yajl/json_gem'
+
+That's right, you can just replace "require 'json'" with the line above and you're done!
+
+This will require yajl-ruby itself, as well as enable it's JSON gem compatibility API.
+
+This includes the following API:
+
+ JSON.parse, JSON.generate, JSON.pretty_generate, JSON.load, JSON.dump
+ and all of the #to_json instance method overrides for Ruby's primitive objects
+
+Once the compatibility API is enabled, you're existing or new project should work as if the JSON gem itself were being used. Only you'll be using Yajl ;)
+
+There are a lot more possibilities that I'd love to see other gems/plugins for someday.
+
Some ideas are:
* parsing logs in JSON format
* a Rails plugin (http://github.com/technoweenie/yajl-rails)
* builtin Rails 3 support?
* Rack middleware (ideally the JSON body could be handed to the parser while it's still being received)
@@ -190,16 +220,32 @@
==== Parse Time (from their respective formats)
* Yajl::Parser#parse: 4.33s
* JSON.parse: 5.37s
-* YAML.load_stream: 19.47s
+* YAML.load: 19.47s
==== Encode Time (to their respective formats)
* Yajl::Encoder#encode: 3.47s
* JSON#to_json: 6.6s
* YAML.dump(obj, io): 1309.93s
+
+=== Compared to Marshal.load/Marshal.dump
+
+NOTE: I converted the 2.4MB JSON file to a Hash and a dump file from Marshal.dump for this test.
+
+==== Parse Time (from their respective formats)
+
+* Yajl::Parser#parse: 4.54s
+* JSON.parse: 7.40s
+* Marshal.load: 7s
+
+==== Encode Time (to their respective formats)
+
+* Yajl::Encoder#encode: 2.39s
+* JSON#to_json: 8.37s
+* Marshal.dump: 4.66s
== Third Party Sources Bundled
This project includes code from the BSD licensed yajl project, copyright 2007-2009 Lloyd Hilaiel
\ No newline at end of file