summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorKenta Murata <mrkn@users.noreply.github.com>2020-07-18 23:45:00 +0900
committerGitHub <noreply@github.com>2020-07-18 23:45:00 +0900
commita63f520971787aa7b32b27486e9a5bb732d2814e (patch)
tree3fbd2c243afe9e54f9f2b35330a3a627cec12649 /test/ruby
parent9f60ceec54a8c05d198d1722c65c8a29e4c71e35 (diff)
Optimize Array#max (#3325)
The benchmark result is below: | |compare-ruby|built-ruby| |:---------------|-----------:|---------:| |ary2.max | 38.837M| 40.830M| | | -| 1.05x| |ary10.max | 23.035M| 32.626M| | | -| 1.42x| |ary100.max | 5.490M| 11.020M| | | -| 2.01x| |ary500.max | 1.324M| 2.679M| | | -| 2.02x| |ary1000.max | 699.167k| 1.403M| | | -| 2.01x| |ary2000.max | 284.321k| 570.446k| | | -| 2.01x| |ary3000.max | 282.613k| 571.683k| | | -| 2.02x| |ary5000.max | 145.120k| 285.546k| | | -| 1.97x| |ary10000.max | 72.102k| 142.831k| | | -| 1.98x| |ary20000.max | 36.065k| 72.077k| | | -| 2.00x| |ary50000.max | 14.343k| 29.139k| | | -| 2.03x| |ary100000.max | 7.586k| 14.472k| | | -| 1.91x| |ary1000000.max | 726.915| 1.495k| | | -| 2.06x|
Notes
Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_array.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index a66d2301d0..2b48dcf308 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1756,10 +1756,12 @@ class TestArray < Test::Unit::TestCase
end
def test_max
+ assert_equal(1, [1].max)
assert_equal(3, [1, 2, 3, 1, 2].max)
assert_equal(1, [1, 2, 3, 1, 2].max {|a,b| b <=> a })
cond = ->((a, ia), (b, ib)) { (b <=> a).nonzero? or ia <=> ib }
assert_equal([1, 3], [1, 2, 3, 1, 2].each_with_index.max(&cond))
+ assert_equal(3.0, [1.0, 3.0, 2.0].max)
ary = %w(albatross dog horse)
assert_equal("horse", ary.max)
assert_equal("albatross", ary.max {|a,b| a.length <=> b.length })
@@ -1777,6 +1779,7 @@ class TestArray < Test::Unit::TestCase
end
def test_minmax
+ assert_equal([3, 3], [3].minmax)
assert_equal([1, 3], [1, 2, 3, 1, 2].minmax)
assert_equal([3, 1], [1, 2, 3, 1, 2].minmax {|a,b| b <=> a })
cond = ->((a, ia), (b, ib)) { (b <=> a).nonzero? or ia <=> ib }