Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "memory_profiler"
- mem = MemoryProfiler.report do
- array = [*1..1_000_000]
- end
- mem2 = MemoryProfiler.report do
- array = [*1..1_000_000]
- b = array.select {|x| x % 3 == 0}
- end
- mem3 = MemoryProfiler.report do
- array = [*1..1_000_000]
- b = []
- 1.upto(1_000_000) {|i| b << i if i % 3 == 0 }
- end
- puts mem.allocated_memory_by_class.first
- puts mem2.allocated_memory_by_class.first
- puts mem3.allocated_memory_by_class.first
- #{:data=>"Array", :count=>19636352}
- #{:data=>"Array", :count=>27636392}
- #{:data=>"Array", :count=>23084168}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement