Created
May 16, 2017 09:51
-
-
Save quanon/cad21de76f6aa21981fd961a1df58ea3 to your computer and use it in GitHub Desktop.
lazy or not lazy
This file contains hidden or 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
# 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) |
This file contains hidden or 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
# 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