Sha256: 213ae8c60b31aa8b4952999ba1dc074a485f4bafeb0badf096af80aaeda8a45e

Contents?: true

Size: 996 Bytes

Versions: 4

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

require_relative 'setup'

unless Dry::Logic::Rule.respond_to?(:build)
  Dry::Logic::Rule.singleton_class.alias_method(:build, :new)
end

predicates = Dry::Logic::Predicates

type_check = Dry::Logic::Rule.build(predicates[:type?]).curry(Integer)
int_check = Dry::Logic::Rule.build(predicates[:int?])
key_check = Dry::Logic::Rule.build(predicates[:key?]).curry(:user)
with_user = { user: {} }
without_user = {}

comparison = Dry::Logic::Rule.build(predicates[:gteq?]).curry(18)

Benchmark.ips do |x|
  x.report("type check - success") { type_check.(0) }
  x.report("type check - failure") { type_check.('0') }
  x.report("int check - success") { int_check.(0) }
  x.report("int check - failure") { int_check.('0') }
  x.report("key check - success") { key_check.(with_user) }
  x.report("key check - failure") { key_check.(without_user) }
  x.report("comparison - success") { comparison.(20) }
  x.report("comparison - failure") { comparison.(17) }

  x.compare!
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-1.0.5 benchmarks/rule_application.rb
dry-logic-1.0.4 benchmarks/rule_application.rb
dry-logic-1.0.3 benchmarks/rule_application.rb
dry-logic-1.0.2 benchmarks/rule_application.rb