Skip to content

Instantly share code, notes, and snippets.

@solutus
Created Jun 18, 2014
Embed
What would you like to do?
#!/usr/bin/env ruby
# Simple script, sorting tests by duration to analyze slow tests.
# Usage:
# chmod +x sort_tests.sh
# rspec -f d spec/ | sort_tests.sh
data = []
prev_time = nil
while input = ARGF.gets
input.each_line do |line|
time_diff = ((Time.now - (prev_time || Time.now)) * 1000).to_i
prev_time = Time.now
data << [time_diff, line]
end
end
data = data.sort_by { |x| x[0] }
begin
data.each do |diff, line|
$stdout.puts [diff, line].join("\t")
end
$stdout.puts "total time: #{data.map {|x| x[0]}.inject(&:+)} ms"
rescue Errno::EPIPE
exit(74)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment