-
-
Save isqad/08903d016c89016a39d1 to your computer and use it in GitHub Desktop.
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 'benchmark/ips' | |
require 'active_support/core_ext' | |
require 'jbuilder' | |
require 'rabl' | |
require 'oj' | |
Benchmark.ips do |benchmark| | |
struct = Struct.new(:name, :birthyear, :bio, :url) | |
@author = struct.new("Rolf", 1920, "Software developer", "http://example.com/") | |
@authors = Array.new(10, @author) | |
# for jbuilder | |
@author.instance_eval { undef map } | |
# for rabl | |
@scope = Object.new | |
@scope.instance_variable_set :@author, @author | |
@template_for_single_object = %{ | |
object @author => :author | |
attribute :name, :birthyear, :bio, :url | |
} | |
@scope.instance_variable_set :@authors, @authors | |
@template_for_collection = %{ | |
collection @authors => :authors | |
attributes :name, :birthyear, :bio, :url | |
} | |
benchmark.report "Jbuilder(single obj)" do | |
Jbuilder.encode do |json| | |
json.author @author, :name, :birthyear, :bio, :url | |
end | |
end | |
benchmark.report "Rabl(single obj)" do | |
Rabl::Engine.new(@template_for_single_object).render(@scope, {}) | |
end | |
benchmark.report "Jbuilder(collection)" do | |
Jbuilder.encode do |json| | |
json.authors @authors do |author| | |
json.author author, :name, :birthyear, :bio, :url | |
end | |
end | |
end | |
benchmark.report "Rabl(collection)" do | |
Rabl::Engine.new(@template_for_collection).render(@scope, {}) | |
end | |
end |
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
source 'https://rubygems.org' | |
gem 'benchmark-ips' | |
gem 'activesupport' | |
gem 'jbuilder' | |
gem 'rabl' | |
gem 'oj' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
activesupport (4.0.2) | |
i18n (~> 0.6, >= 0.6.4) | |
minitest (~> 4.2) | |
multi_json (~> 1.3) | |
thread_safe (~> 0.1) | |
tzinfo (~> 0.3.37) | |
atomic (1.1.14) | |
benchmark-ips (1.2.0) | |
i18n (0.6.9) | |
jbuilder (2.0.2) | |
activesupport (>= 3.0.0) | |
multi_json (>= 1.2.0) | |
minitest (4.7.5) | |
multi_json (1.8.4) | |
oj (2.5.4) | |
rabl (0.9.3) | |
activesupport (>= 2.3.14) | |
thread_safe (0.1.3) | |
atomic | |
tzinfo (0.3.38) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
activesupport | |
benchmark-ips | |
jbuilder | |
oj | |
rabl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment