Created
September 5, 2012 15:15
-
-
Save rolftimmermans/3638182 to your computer and use it in GitHub Desktop.
Jbuilder benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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