Skip to content

Instantly share code, notes, and snippets.

@quanon
Created May 16, 2017 09:51
Show Gist options
  • Save quanon/cad21de76f6aa21981fd961a1df58ea3 to your computer and use it in GitHub Desktop.
Save quanon/cad21de76f6aa21981fd961a1df58ea3 to your computer and use it in GitHub Desktop.
lazy or not lazy
# frozen_string_literal: true
require 'memory_profiler'
require 'resolv'
report = MemoryProfiler.report do
# $ wc -l development.log
# 1000000 development.log
open('development.log') do |f|
f
.each_line
.lazy
.map { |line| line.scrub('?') } # avoid invalid byte sequence in UTF-8
.map { |line| line[/\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/] }
.select { |ip_addr| ip_addr }
.take(100)
end
end
report.pretty_print
# Total allocated: 3080 bytes (38 objects)
# frozen_string_literal: true
require 'memory_profiler'
require 'resolv'
report = MemoryProfiler.report do
# $ wc -l development.log
# 1000000 development.log
open('development.log') do |f|
f
.each_line
.map { |line| line.scrub('?') } # avoid invalid byte sequence in UTF-8
.map { |line| line[/\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/] }
.select { |ip_addr| ip_addr }
.take(100)
end
end
report.pretty_print
# Total allocated: 319791009 bytes (3024548 objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment