Skip to content

Instantly share code, notes, and snippets.

@daniel-beard
Last active April 14, 2019 11:37
Show Gist options
  • Save daniel-beard/3a614435c202d03c8338a5d53a1e333e to your computer and use it in GitHub Desktop.
Save daniel-beard/3a614435c202d03c8338a5d53a1e333e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'json'
# http://danielbeard.io/2016/08/17/swift-file-compile-times.html
# Helper function to parse filename
def parse(input)
result = ""
processing_space_escape = false
input.each_char { |c|
if c == '\\'
result += c
processing_space_escape = true
elsif c == ' ' && processing_space_escape == true
result += c
processing_space_escape = false
elsif c == ' ' && processing_space_escape == false
return result
else
result += c
end
}
return result
end
compiling_swift_file = false
current_filename = ""
current_offset = 0
# all stdin lines
ARGF.each do |line|
# Wait until we hit a CompileSwift file
if line =~ /^[\s]*CompileSwift[\s]+/
compiling_swift_file = true
current_filename = parse(line[line.index('/')..-1]).chomp
end
# If we get here and aren't currently compiling a swift file, skip all else
if compiling_swift_file == false
next
end
# Ignore everything until we hit the "Swift compilation line"
if current_offset == 0 && line =~ /Swift compilation/
current_offset = 1
elsif current_offset >= 1
current_offset += 1
# This line has the total elapsed time.
if current_offset == 3
wall_time = line.gsub(/^.*\(/, '').match(/[-+]?[0-9]*\.?[0-9]+/) # Second fp value is the one we want.
puts "#{wall_time}s #{current_filename}"
compiling_swift_file = false
current_filename = ""
current_offset = 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment