Created
August 14, 2014 22:52
-
-
Save elskwid/0f928d6685dc8feb34bf to your computer and use it in GitHub Desktop.
Virtus speed comparison
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
> be ruby coerce-speed.rb | |
Rehearsal ------------------------------------------------------- | |
Poro 0.020000 0.000000 0.020000 ( 0.025502) | |
MongoidDoc 0.460000 0.000000 0.460000 ( 0.464085) | |
VirtusModel 0.210000 0.010000 0.220000 ( 0.219621) | |
VirtusModelNoCoerce 0.060000 0.000000 0.060000 ( 0.062512) | |
---------------------------------------------- total: 0.760000sec | |
user system total real | |
Poro 0.010000 0.000000 0.010000 ( 0.004206) | |
MongoidDoc 0.420000 0.010000 0.430000 ( 0.430198) | |
VirtusModel 0.210000 0.000000 0.210000 ( 0.242876) | |
VirtusModelNoCoerce 0.050000 0.000000 0.050000 ( 0.056276) |
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" | |
require "mongoid" # v4.0.0 | |
require "virtus" # v1.0.3 | |
# Ruby 2.1.2 | |
class Poro | |
attr_accessor :foo | |
end | |
class MongoidDoc | |
include Mongoid::Document | |
field :foo, :type => String | |
end | |
class VirtusModel | |
include Virtus.model | |
attribute :foo, String | |
end | |
class VirtusModelNoCoerce | |
include Virtus.model(coerce: false) | |
attribute :foo, String | |
end | |
models = [Poro, MongoidDoc, VirtusModel, VirtusModelNoCoerce] | |
n = 10000 | |
Benchmark.bmbm do |x| | |
models.each do |model| | |
x.report(model.to_s) do | |
n.times do | |
m = model.new | |
m.foo = "foo" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment