Created
October 12, 2018 01:08
-
-
Save schneems/78164e61485bf3d130e35e7347d61ae0 to your computer and use it in GitHub Desktop.
This file contains 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/ips' | |
| |
MYARRAY = [["a", ["b", nil, "c", ["d"]]]] | |
| |
Benchmark.ips do |x| | |
x.report("before") { | |
array = MYARRAY.dup | |
array.flatten! | |
array.uniq! | |
array.compact! | |
array | |
} | |
x.report("after ") { | |
array = MYARRAY.dup | |
array.tap(&:flatten!).tap(&:uniq!).tap(&:compact!) | |
} | |
x.compare! | |
end | |
# Warming up -------------------------------------- | |
# before 35.455k i/100ms | |
# after 32.321k i/100ms | |
# Calculating ------------------------------------- | |
# before 393.043k (± 4.5%) i/s - 1.985M in 5.062618s | |
# after 371.538k (± 2.2%) i/s - 1.875M in 5.048124s | |
| |
# Comparison: | |
# before: 393043.0 i/s | |
# after : 371537.7 i/s - same-ish: difference falls within error | |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment