Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created September 1, 2017 05:43
Show Gist options
  • Save a2ikm/9046ee14aaa7eb9b606e78e556c12e66 to your computer and use it in GitHub Desktop.
Save a2ikm/9046ee14aaa7eb9b606e78e556c12e66 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "terminal-table"
slim_path = ARGV[0]
fat_path = ARGV[1]
def parse_objects(path)
ok = false
counts = {}
File.read(path).split("\n").each do |line|
if line.include?("All objects:")
ok = true
next
end
if line.include?("bytes")
ok = false
next
end
unless ok
next
end
count, klass = line.strip.split(": ")
count.gsub!(",", "")
counts[klass] = count.to_i
end
counts
end
slim_counts = parse_objects(slim_path)
fat_counts = parse_objects(fat_path)
result = {}
(slim_counts.keys + fat_counts.keys).uniq.each do |klass|
slim_count = slim_counts[klass] || 0
fat_count = fat_counts[klass] || 0
diff_count = fat_count - slim_count
next if diff_count == 0
result[klass] = { diff: diff_count, slim: slim_count, fat: fat_count }
end
len = 120
klasses = result.keys.sort_by { |klass| result[klass][:diff] }.reverse
table = Terminal::Table.new do |t|
t.add_row %w(Class Diff Slim Fat)
t.add_separator
klasses.each do |klass|
data = result[klass]
title = klass
title = title[0, len] + "..." if title.length > len
t.add_row [title, data[:diff], data[:slim], data[:fat]]
end
end
puts table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment