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
# Info: | |
# | |
# A performance benchmark of `Set` vs `Array` on a 5 integer element data set*. | |
# | |
# S: a class INSTANTIATED containing a Set INSTANTIATED for each `include?` query | |
# A: a class INSTANTIATED with an already instantiated Array for each `include?` query | |
# SS: an already instantiated class with an already instantiated Set for each `include?` query | |
# AA: an already instantiated class with an already instantiated Array for each `include?` query | |
# | |
# For pure comparison purposes of Set and Array, you should only pay attention to SS and AA benchmarks. |
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' | |
loops = 1_000_000 | |
str = 'whatever/string/like/this' | |
Benchmark.bm do |x| | |
x.report 'michal1' do | |
loops.times do | |
str.split('/').reduce([]){ |acc, v| acc.push(([acc.last].compact + [v]).flatten) } |
NewerOlder