-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,6 @@ group :benchmarks do | |
gem "fast_attributes" | ||
gem "hotch" | ||
gem "virtus" | ||
gem "activemodel" | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_model" | ||
require "benchmark/ips" | ||
require "dry/types" | ||
|
||
am = ActiveModel::Type::Date.new | ||
dry = Dry::Types["params.date"] | ||
|
||
["2020-01-20", "3rd Feb 2001"].each do |d| | ||
Benchmark.ips do |x| | ||
x.report("DRY #{d}") do |n| | ||
while n > 0 | ||
dry[d] | ||
n -= 1 | ||
end | ||
end | ||
|
||
x.report("AM #{d}") do |n| | ||
while n > 0 | ||
am.cast(d) | ||
n -= 1 | ||
end | ||
end | ||
|
||
x.compare! | ||
end | ||
end | ||
|
||
# before | ||
# | ||
# Comparison: | ||
# AM 2020-01-20: 712594.2 i/s | ||
# DRY 2020-01-20: 234735.9 i/s - 3.04x (± 0.00) slower | ||
# | ||
# Comparison: | ||
# DRY 3rd Feb 2001: 148000.4 i/s | ||
# AM 3rd Feb 2001: 140262.5 i/s - same-ish: difference falls within error | ||
|
||
# after | ||
# | ||
# Comparison: | ||
# AM 2020-01-20: 694511.8 i/s | ||
# DRY 2020-01-20: 692906.6 i/s - same-ish: difference falls within error | ||
# | ||
# Comparison: | ||
# DRY 3rd Feb 2001: 141146.9 i/s | ||
# AM 3rd Feb 2001: 139686.5 i/s - same-ish: difference falls within error |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require "benchmark/ips" | ||
require "dry/types" | ||
require "active_model" | ||
require "active_support/core_ext/time/zones" | ||
require 'pry' | ||
|
||
::Time.zone_default = "Moscow" | ||
am = ActiveModel::Type::Time.new | ||
dry = Dry::Types["params.time"] | ||
|
||
["2020-01-20 19:40:22", "2021-02-03T00:10:54.597+03:00", "Thu Nov 29 14:33:20 2001"].each do |d| | ||
Benchmark.ips do |x| | ||
x.report("DRY #{d}") do |n| | ||
while n > 0 | ||
dry[d] | ||
n -= 1 | ||
end | ||
end | ||
|
||
x.report("AM #{d}") do |n| | ||
while n > 0 | ||
am.cast(d) | ||
n -= 1 | ||
end | ||
end | ||
|
||
x.compare! | ||
end | ||
end | ||
|
||
|
||
# before | ||
# | ||
# Comparison: | ||
# AM 2020-01-20 19:40:22: 130660.9 i/s | ||
# DRY 2020-01-20 19:40:22: 58853.9 i/s - 2.22x (± 0.00) slower | ||
# | ||
# Comparison: | ||
# DRY 2021-02-03T00:10:54.597+03:00: 52110.0 i/s | ||
# AM 2021-02-03T00:10:54.597+03:00: 39652.9 i/s - 1.31x (± 0.00) slower | ||
# | ||
# Comparison: | ||
# DRY Thu Nov 29 14:33:20 2001: 44819.1 i/s | ||
# AM Thu Nov 29 14:33:20 2001: 33064.5 i/s - 1.36x (± 0.00) slower | ||
|
||
# after | ||
# | ||
# Comparison: | ||
# DRY 2020-01-20 19:40:22: 190951.9 i/s | ||
# AM 2020-01-20 19:40:22: 131920.6 i/s - 1.45x (± 0.00) slower | ||
# | ||
# Comparison: | ||
# DRY 2021-02-03T00:10:54.597+03:00: 157549.5 i/s | ||
# AM 2021-02-03T00:10:54.597+03:00: 40502.8 i/s - 3.89x (± 0.00) slower | ||
# | ||
# Comparison: | ||
# DRY Thu Nov 29 14:33:20 2001: 44376.3 i/s | ||
# AM Thu Nov 29 14:33:20 2001: 33955.3 i/s - 1.31x (± 0.00) slower |
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