Skip to content

Instantly share code, notes, and snippets.

@goshacmd
Created January 1, 2013 17:34
Show Gist options
  • Save goshacmd/4428843 to your computer and use it in GitHub Desktop.
Save goshacmd/4428843 to your computer and use it in GitHub Desktop.
require 'benchmark'
# Benchmarking Array#compact & Array#join
n = 1_000_000
Benchmark.bm do |x|
x.report('3 elements + nil') { n.times { ['a', 'b', 'c', nil].compact.join('::') } }
x.report('3 elements') { n.times { ['a', 'b', 'c'].compact.join('::') } }
end
# user system total real
# 3 elements + nil 2.170000 0.040000 2.210000 ( 2.217473)
# 3 elements 1.860000 0.040000 1.900000 ( 1.888981)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment