-
-
Save eregon/c65e3b8071a439a3e4d7c3bd6818fc3e to your computer and use it in GitHub Desktop.
This file contains 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
puts RUBY_DESCRIPTION | |
require 'benchmark' | |
N = Integer(ARGV[0] || 50_000_000) | |
content = "Accept-Language: fr-FR, en-US#{"0" * N}" | |
def print_size(context, sike_kb) | |
puts "#{context}: #{(sike_kb / 1024.0).round(1)} MB" | |
end | |
print_size("baseline", `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i).last) | |
print_size("content", content.bytesize / 1024) | |
REGEXP_UNION = Regexp.union( | |
"Accept-Language:", | |
"Thread-Topic:", | |
).freeze | |
reg = /.*#{REGEXP_UNION}/ | |
p reg | |
GC.start | |
print_size("before match?", `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i).last) | |
allocated = GC.stat(:total_allocated_objects) | |
p Benchmark.realtime { | |
p content.match(reg) | |
} | |
p GC.stat(:total_allocated_objects) - allocated | |
GC.start | |
print_size("after match?", `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i).last) | |
p "---" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment