Skip to content

Instantly share code, notes, and snippets.

@pocke
Created November 26, 2016 01:32
Show Gist options
  • Save pocke/7a0b580d612002fd09c5c397d91250b0 to your computer and use it in GitHub Desktop.
Save pocke/7a0b580d612002fd09c5c397d91250b0 to your computer and use it in GitHub Desktop.
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