Skip to content

Instantly share code, notes, and snippets.

@RX14
Created May 9, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RX14/db69279bbc4a3834f6300acb79c9f0e4 to your computer and use it in GitHub Desktop.
Save RX14/db69279bbc4a3834f6300acb79c9f0e4 to your computer and use it in GitHub Desktop.
require "benchmark"
RANGE = (1..100)
def slow
RANGE.map { |i| i.to_s }
end
def fast
RANGE.map(&.to_s)
end
Benchmark.ips do |x|
x.report("Block") { slow }
x.report("Symbol#to_proc") { fast }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment