Skip to content

Instantly share code, notes, and snippets.

@eprothro
Last active February 29, 2016 19:05
Show Gist options
  • Save eprothro/811d2535468db0d11e53 to your computer and use it in GitHub Desktop.
Save eprothro/811d2535468db0d11e53 to your computer and use it in GitHub Desktop.
# Serializing 1 string attribute, 1 overriden uuid.to_s attribute,
# and 1 empty array, 30 times.
# bmbm:
# user system total real
# serializer 0.010000 0.000000 0.010000 ( 0.002572)
# delegator 0.000000 0.000000 0.000000 ( 0.000424)
# ips:
# delegator: 3600.6 i/s
# serializer: 427.6 i/s - 8.42x slower
#
# 3ms here is not insignificant when projecting
# to much larger json payloads. Considering that
# AMS isn't much easier to use or more flexible than
# simple decorators and, more importantly, this is not
# something that changes much (an API's format), I don't
# see a lot of value in the adapter abstraction that we lose.
messages = Array.new(30) do
Message.new(id: Cassandra::Uuid.new(SecureRandom.uuid), foo: 'some text')
end and ''
Benchmark.ips do |r|
r.config(:time => 1, :warmup => 0)
r.report('delegator') do
messages.each do |message|
DelegatorMessageSerializer.new(message).serializable_hash.as_json
end
end
r.report('serializer') do
messages.each do |message|
ActiveModel::SerializableResource.new(message, serializer: SerializerMessageSerializer).serializable_hash.as_json
end
end
r.compare!
end and ''
@eprothro
Copy link
Author

with AMS 10.x, AMS 8.x much faster, but not the trunk path for development any longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment