Skip to content

Instantly share code, notes, and snippets.

@solutus
Created June 18, 2014 11:09
Show Gist options
  • Save solutus/74d0c353a83bbb8d8f64 to your computer and use it in GitHub Desktop.
Save solutus/74d0c353a83bbb8d8f64 to your computer and use it in GitHub Desktop.
#!/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