-
-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathcoercions_time.rb
More file actions
60 lines (52 loc) · 1.4 KB
/
coercions_time.rb
File metadata and controls
60 lines (52 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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