Skip to content

Instantly share code, notes, and snippets.

@rolftimmermans
Created September 5, 2012 15:15
Show Gist options
  • Save rolftimmermans/3638182 to your computer and use it in GitHub Desktop.
Save rolftimmermans/3638182 to your computer and use it in GitHub Desktop.
Jbuilder benchmark
require "active_support/core_ext"
def build_json(n)
struct = Struct.new(:name, :birthyear, :bio, :url)
author = struct.new("Rolf", 1920, "Software developer", "http://example.com/")
author.instance_eval { undef each } # Jbuilder doesn't like #each on non-arrays.
now = Time.now
arr = 100.times.to_a
n.times do
json = Jbuilder.encode do |json|
json.article do |json|
json.author(author, :name, :birthyear, :bio)
json.title "Profiling Jbuilder"
json.body "How to profile Jbuilder"
json.date now
json.references arr do |json, ref|
json.name "Introduction to profiling"
json.url "http://example.com/"
end
json.comments arr do |json, comment|
json.author(author, :name, :birthyear, :bio)
json.email "[email protected]"
json.body "Great article"
json.date now
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment