Skip to content

Instantly share code, notes, and snippets.

View unleashed's full-sized avatar
👶
Parenting x2

Alejandro Martinez Ruiz unleashed

👶
Parenting x2
View GitHub Profile
@unleashed
unleashed / set_vs_array.rb
Last active August 29, 2015 14:17
Set vs Array with small data set // Cost of Set creation on top of Array
# 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.
@unleashed
unleashed / benchmark.rb
Created September 3, 2014 15:01
mikz: does anyway have better way of converting whatever/string/like/this to [['whatever'], ['whatever', 'string'], ['whatever', 'string', 'like'], ['whatever', 'string', 'like', 'this']] than: str.split('/').reduce([]){ |acc, v| acc.push(([acc.last].compact + [v]).flatten) }
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) }