Skip to content

Instantly share code, notes, and snippets.

@carlosparamio
Created September 30, 2013 13:41
Show Gist options
  • Save carlosparamio/6763984 to your computer and use it in GitHub Desktop.
Save carlosparamio/6763984 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'api_smith'
require 'virtus'
class StructData < Struct.new(:id, :date, :boolean)
end
class APISmithData < APISmith::Smash
property :id
property :date
property :boolean
end
class VirtusData
include Virtus.model
attribute :id, Integer
attribute :date, DateTime
attribute :boolean, Boolean
end
n = 1_000_000
now = Time.now
Benchmark.bmbm do |x|
x.report("struct") do
n.times { StructData.new(id: 1, date: now, boolean: true) }
end
x.report("api_smith") do
n.times { APISmithData.new(id: 1, date: now, boolean: true) }
end
x.report("virtus") do
n.times { VirtusData.new(id: 1, date: now, boolean: true) }
end
end
Rehearsal ---------------------------------------------
struct 0.800000 0.110000 0.910000 ( 0.908901)
api_smith 11.370000 0.030000 11.400000 ( 11.416546)
virtus 62.730000 0.080000 62.810000 ( 62.869756)
----------------------------------- total: 75.120000sec
user system total real
struct 0.780000 0.030000 0.810000 ( 0.816881)
api_smith 11.130000 0.010000 11.140000 ( 11.157779)
virtus 60.450000 0.030000 60.480000 ( 60.487696)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment