LoginSignup
52
50

More than 5 years have passed since last update.

Swift のメソッド毎のコンパイル時間の計測結果を見やすく表示するスクリプト

Posted at

Xcode - Swiftのメソッド毎のコンパイル時間を計測してビルド時間を短縮する - Qiita がすごく便利そうなので試してみたのですが、結果のテキストが長すぎたのでコンパイル時間の長い順に表示するスクリプトを書きました。

ついでに cocoapods 管理下のファイルは結果に含めないようにしてみました。

スクリプトはこちら

使い方

元記事と同様に以下を実行

  • Other Swift Flagsに -Xfrontend -debug-time-function-bodies を追加
  • xctool -workspace './xyz.xcworkspace' -scheme 'SchemeName' -jobs 1 clean build | tee build_in_detail.txt 1

生成されたビルド結果のテキストファイルで

  • cat build_in_detail.txt | perl -pe 's/\x1b.*?[mGKH]//g' | ruby swift_build_log_parser.rb 2

とすることで

=== File ===
  8294ms SomeView
  6729ms MainViewController
  6513ms MainViewController
  5469ms SomeView
  1067ms Fridge
  1051ms Fridge
   922ms AppDelegate
   914ms API
   869ms API
   609ms OneModel
...
...

=== Method ===
  5932.1ms SomeView.swift:98:10 func currentPosition(model: OneModel) -> CGPoint
  4896.7ms SomeView.swift:98:10 func currentPosition(model: OneModel) -> CGPoint
  3924.1ms MainViewController.swift:280:10 @objc func syncWithRemote(state: Int)
  3921.6ms MainViewController.swift:286:79 (closure)
  3911.8ms MainViewController.swift:326:56 (closure)
  3713.8ms MainViewController.swift:280:10 @objc func syncWithRemote(state: Int)
  3712.0ms MainViewController.swift:286:79 (closure)
  3705.3ms MainViewController.swift:326:56 (closure)
  1560.1ms MainViewController.swift:207:10 @objc func bindDynamically(isInit: Bool)
  1491.9ms MainViewController.swift:207:10 @objc func bindDynamically(isInit: Bool)
...
...

=== Build time ===
414618 ms

こんな感じで結果を整理することができます。

感想

関数を大きくしすぎないことは、人間にとっての Readability のみならず、型推論をするコンパイラにとっての Readabilty も向上させるのだなと思いました。


  1. ビルド時間がかなりかかるので tee をかませた 

  2. エスケープシーケンスを手軽に除去するコマンドとかってないのかなー 

52
50
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
52
50