Created
February 13, 2013 08:38
-
-
Save kapkaev/4943119 to your computer and use it in GitHub Desktop.
oj vs activemodel_serializer
This file contains hidden or 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' | |
require 'oj' | |
class WrapperSerializer < ActiveModel::Serializer | |
attributes :seq | |
end | |
class Wrapper | |
include ActiveModel::SerializerSupport | |
def initialize | |
@seq = [] | |
100.times {@seq << A.new} | |
end | |
attr_accessor :seq | |
end | |
class A | |
include ActiveModel::SerializerSupport | |
def initialize | |
@x = 1 | |
@y = 2 | |
@z = B.new | |
end | |
attr_accessor :x, :y, :z | |
end | |
class B | |
include ActiveModel::SerializerSupport | |
def initialize | |
@x = 1 | |
@y = 2 | |
@z = C.new | |
end | |
attr_accessor :x, :y, :z | |
end | |
class C | |
include ActiveModel::SerializerSupport | |
def initialize | |
@x = 1 | |
@y = 2 | |
end | |
attr_accessor :x, :y, :z | |
end | |
Benchmark.realtime { Oj.dump(Wrapper.new ) } | |
Benchmark.realtime { Oj.dump(Wrapper.new, {:mode => :compat}) } | |
Benchmark.realtime { WrapperSerializer.new(Wrapper.new).as_json} | |
Benchmark.realtime { WrapperSerializer.new(Wrapper.new).to_json} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment