Created
November 26, 2016 01:32
-
-
Save pocke/7a0b580d612002fd09c5c397d91250b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| Benchmark.bm(20) do |x| | |
| array = (1..100000).map { rand(100000) } | |
| x.report('10000 max_by'){100.times{array.max_by{|x| x.to_s}}} | |
| x.report('10000 max'){ 100.times{array.max{|a, b| a.to_s <=> b.to_s }}} | |
| x.report('10000 min_by'){100.times{array.min_by{|x| x.to_s}}} | |
| x.report('10000 min'){ 100.times{array.min{|a, b| a.to_s <=> b.to_s }}} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment