diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2015-07-30 15:12:37 -0400 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2015-07-30 15:12:37 -0400 |
commit | 32133db710600d66f41e998359328b8e6104630b (patch) | |
tree | 0934ec6fc1f935deb517fc9e8f3f1ca8e5e974ba /actionpack/lib/abstract_controller/helpers.rb | |
parent | 5373bf228d1273deae0ed03370ec4a63c580422b (diff) | |
download | rails-32133db710600d66f41e998359328b8e6104630b.tar.gz rails-32133db710600d66f41e998359328b8e6104630b.tar.bz2 rails-32133db710600d66f41e998359328b8e6104630b.zip |
Array#any? is slower and not the inverse of Array#empty?
```
empty_array = []
small_array = [1] * 30
bigger_array = [1] * 300
Benchmark.ips do |x|
x.report('empty !empty?') { !empty_array.empty? }
x.report('small !empty?') { !small_array.empty? }
x.report('bigger !empty?') { !bigger_array.empty? }
x.report('empty any?') { empty_array.any? }
x.report('small any?') { small_array.any? }
x.report('bigger any?') { bigger_array.any? }
end
```
```
Calculating -------------------------------------
empty !empty? 132.059k i/100ms
small !empty? 133.974k i/100ms
bigger !empty? 133.848k i/100ms
empty any? 106.924k i/100ms
small any? 85.525k i/100ms
bigger any? 86.663k i/100ms
-------------------------------------------------
empty !empty? 8.522M (± 7.9%) i/s - 42.391M
small !empty? 8.501M (± 8.5%) i/s - 42.202M
bigger !empty? 8.434M (± 8.6%) i/s - 41.894M
empty any? 4.161M (± 8.3%) i/s - 20.743M
small any? 2.654M (± 5.2%) i/s - 13.256M
bigger any? 2.642M (± 6.4%) i/s - 13.173M
```
Ref: https://github.com/rails/rails/pull/21057#discussion_r35902468
Diffstat (limited to 'actionpack/lib/abstract_controller/helpers.rb')
0 files changed, 0 insertions, 0 deletions