Skip to content

Instantly share code, notes, and snippets.

@jchris
Forked from brianmario/gist:117379
Created May 25, 2009 05:07
Show Gist options
  • Save jchris/117388 to your computer and use it in GitHub Desktop.
Save jchris/117388 to your computer and use it in GitHub Desktop.
require 'lib/yajl/http_stream'
require 'uri'
uri = URI.parse('http://jchrisa.net/toast/_changes')
Yajl::HttpStream.get(uri) do |hash|
# will take a few seconds, since the response is a single ~4MB JSON string
# if the response was a bunch of individual JSON strings, this would be fired
# for every string parsed off the stream, as they were parsed
puts hash.inspect
end
# For comparison
# ==============
#
# Download & Parse
# ----------------
# time ruby test.rb
# real 0m8.685s
# user 0m1.228s
# sys 0m0.198s
#
# Download Only
# -------------
# time curl http://jchrisa.net/toast/_all_docs_by_seq?include_docs=true > /dev/null
# real 0m8.587s
# user 0m0.067s
# sys 0m0.211s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment