Permalink
Browse files

Add Jbuilder example to benchmarks.

  • Loading branch information...
1 parent ec7d1af commit bb2573fec7dc72f6c9c575971e8f1db620c61f1e @mdub committed Aug 21, 2012
Showing with 21 additions and 2 deletions.
  1. +21 −2 benchmark/benchmark.rb
View
@@ -8,6 +8,8 @@
require "benchmark"
require "ostruct"
+require "jbuilder"
+
require "representative/json"
require "representative/nokogiri"
require "representative/xml"
@@ -38,7 +40,7 @@
class RepresentativeBenchmark < Clamp::Command
- ALL_STRATEGIES = %w(builder nokogiri json to_json)
+ ALL_STRATEGIES = %w(builder nokogiri json to_json jbuilder)
def self.validate_strategy(strategy)
unless ALL_STRATEGIES.member?(strategy)
@@ -128,7 +130,7 @@ def with_nokogiri
end
def with_json
- r = Representative::Json.new
+ r = Representative::Json.new(nil, :indentation => false)
represent_books_using(r)
r.to_json
end
@@ -149,6 +151,23 @@ def with_to_json
book_data.to_json
end
+ def with_jbuilder
+ Jbuilder.encode do |json|
+ json.array!($books) do |json, book|
+ json.title(book.title)
+ json.authors(book.authors)
+ if book.published
+ json.published do |json|
+ json.by(book.published.by)
+ json.year(book.published.year)
+ end
+ else
+ json.published(nil)
+ end
+ end
+ end
+ end
+
end
RepresentativeBenchmark.run

0 comments on commit bb2573f

Please sign in to comment.