Project

General

Profile

Feature #15151 ยป bench_slice_bang.rb

chopraanmol1 (Anmol Chopra), 09/23/2018 03:32 PM

 
require 'memory_profiler'
require 'benchmark'

def generate_string(times = 1000)
('0'..'z').to_a.join * times
end


def each_str!(string, len = 20)
while (str = string.slice!(0, len)).size > 0
yield str
end
end


string = generate_string
MemoryProfiler.report(top: 0){ each_str!(string){} }.pretty_print(detailed_report: false)


string = generate_string
puts Benchmark.measure{ each_str!(string){} }

    (1-1/1)