#none? should be much faster than select#empty?

∴ rake benchmarks:select_empty_versus_none
Calculating -------------------------------------
       select.empty?     2.581k i/100ms
               none?    12.755k i/100ms
-------------------------------------------------
       select.empty?     28.826k (± 6.3%) i/s -    144.536k
               none?    268.873k (± 5.9%) i/s -      1.352M

Comparison:
               none?:   268873.0 i/s
       select.empty?:    28826.3 i/s - 9.33x slower
This commit is contained in:
Jon Atack 2014-12-10 19:25:05 +01:00
parent 3c56371d8f
commit 76191612ad
1 changed files with 1 additions and 1 deletions

View File

@ -71,7 +71,7 @@ module Ransack
end
def validate(vals, type = @type)
vals.select { |v| validator.call(type ? v.cast(type) : v.value) }.any?
vals.any? { |v| validator.call(type ? v.cast(type) : v.value) }
end
end