benchmarks/interactor/service_failure.rb in u-service-0.12.0 vs benchmarks/interactor/service_failure.rb in u-service-0.13.0
- old
+ new
@@ -3,28 +3,31 @@
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips', '~> 2.7', '>= 2.7.2'
gem 'interactor', '~> 3.1', '>= 3.1.1'
- gem 'u-service', '~> 0.11.0'
+ gem 'u-service', '~> 0.12.0'
end
require 'benchmark/ips'
-class MSB_Multiply < Micro::Service::Base
- attributes :a, :b
+class IT_Multiply
+ include Interactor
- def call!
+ def call
+ a = context.a
+ b = context.b
+
if a.is_a?(Numeric) && b.is_a?(Numeric)
- Success(a * b)
+ context.number = a * b
else
- Failure(:invalid_data)
+ context.fail!(type: :invalid_data)
end
end
end
-class MSS_Multiply < Micro::Service::Strict
+class MSB_Multiply < Micro::Service::Base
attributes :a, :b
def call!
if a.is_a?(Numeric) && b.is_a?(Numeric)
Success(a * b)
@@ -32,21 +35,18 @@
Failure(:invalid_data)
end
end
end
-class IT_Multiply
- include Interactor
+class MSS_Multiply < Micro::Service::Strict
+ attributes :a, :b
- def call
- a = context.a
- b = context.b
-
+ def call!
if a.is_a?(Numeric) && b.is_a?(Numeric)
- context.number = a * b
+ Success(a * b)
else
- context.fail!(type: :invalid_data)
+ Failure(:invalid_data)
end
end
end
SYMBOL_KEYS = { a: nil, b: 2 }
@@ -56,38 +56,38 @@
x.config(:time => 5, :warmup => 2)
x.time = 5
x.warmup = 2
+ x.report('Interactor') do
+ IT_Multiply.call(SYMBOL_KEYS)
+ IT_Multiply.call(STRING_KEYS)
+ end
+
x.report('Micro::Service::Base') do
MSB_Multiply.call(SYMBOL_KEYS)
MSB_Multiply.call(STRING_KEYS)
end
x.report('Micro::Service::Strict') do
MSS_Multiply.call(SYMBOL_KEYS)
MSS_Multiply.call(STRING_KEYS)
end
- x.report('Interactor') do
- IT_Multiply.call(SYMBOL_KEYS)
- IT_Multiply.call(STRING_KEYS)
- end
-
x.compare!
end
# Warming up --------------------------------------
-# Micro::Service::Base 5.304k i/100ms
-# Micro::Service::Strict
-# 4.516k i/100ms
# Interactor 1.507k i/100ms
+# Micro::Service::Base 12.902k i/100ms
+# Micro::Service::Strict
+# 9.758k i/100ms
# Calculating -------------------------------------
-# Micro::Service::Base 54.444k (± 2.8%) i/s - 275.808k in 5.070215s
+# Interactor 15.482k (± 2.6%) i/s - 78.364k in 5.065166s
+# Micro::Service::Base 134.861k (± 1.3%) i/s - 683.806k in 5.071263s
# Micro::Service::Strict
-# 45.996k (± 1.8%) i/s - 230.316k in 5.008931s
-# Interactor 15.363k (± 2.2%) i/s - 76.857k in 5.005209s
+# 101.331k (± 1.5%) i/s - 507.416k in 5.008688s
# Comparison:
-# Micro::Service::Base: 54444.5 i/s
-# Micro::Service::Strict: 45995.8 i/s - 1.18x slower
-# Interactor: 15363.0 i/s - 3.54x slower
+# Micro::Service::Base: 134861.1 i/s
+# Micro::Service::Strict: 101331.5 i/s - 1.33x slower
+# Interactor: 15482.0 i/s - 8.71x slower