我能用XCTest測試應用程序中的一個部分的性能嗎?

[英]Can I test performance of one section in my application with XCTest?


As I am little bit aware about UNIT testing with Xcode XCTest target I want to know that in my project, there is one section which contains many animations and many services and database process over there so how to measure performance of that screen in XCTest ?

由於我對Xcode XCTest目標的單元測試有點了解,我想知道在我的項目中,有一個部分包含了很多動畫和許多服務和數據庫過程,那么如何在XCTest中測量該屏幕的性能呢?

2 个解决方案

#1


4  

There are methods for measuring performance in XCTestCase: measure and measureMetrics.

在XCTestCase中有度量性能的方法:度量和度量。

These methods execute the code inside the block ten times and report individual execution times, average time and deviation. They also set a base line for each tested device and report a test failure if the measured part of your code becomes significantly slower in the future.

這些方法在塊內執行代碼10次,並報告單個執行時間、平均時間和偏差。他們還為每個被測試的設備設置基線,並報告一個測試失敗,如果您的代碼的被測試部分在未來明顯變慢。

The Xcode template for Unit Test Case files has one performance test method example at the bottom:

單元測試用例文件的Xcode模板在底部有一個性能測試方法示例:

class CoreDataTestTests: XCTestCase {

    func testPerformanceExample() {
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
}

#2


1  

It depends on what you want to do with the results.

這取決於你想對結果做什么。

If you want to test the performance of your function for some kind of benchmarking to see if things get slower or faster after changes are made to that code, then check what nils suggested.

如果您想要測試函數的性能,以便進行某種基准測試,看看在對代碼進行更改之后,事情是否會變得更慢或更快,那么請檢查nils的建議。

If you want to know what is taking processing time, then you are better off getting the exact measurements using Instruments. You can run Instruments from the Product menu, using Profile or command+i.

如果你想知道什么需要處理時間,那么你最好使用儀器進行精確的測量。您可以使用配置文件或命令+i從產品菜單運行工具。

Choose time profiler and run the process (using the red circle button) on the device. Note that it helps to enable a few settings in order to see the data more clearly.

選擇時間分析器並在設備上運行進程(使用紅色圓圈按鈕)。注意,它有助於啟用一些設置,以便更清楚地查看數據。

Use your app as a user would and observe the call tree in real time as it shows what functions are taking the most processor time.

像用戶一樣使用你的應用,並實時觀察調用樹,因為它顯示了哪些函數占用了最多的處理器時間。

From here you can see what might need optimisation etc.

從這里你可以看到什么可能需要優化等等。

Note: You might need to enable dSYM in your build settings in order to get the symbols rather than random memory offsets in the trace.

注意:您可能需要在構建設置中啟用dSYM,以便在跟蹤中獲得符號,而不是隨機的內存偏移量。

enter image description here

Instruments is a great tool for knowing what is going on in your app. You can check CPU core usage, thread usage and thread waiting etc.

儀器是一個很好的工具,可以了解你的應用正在發生什么。你可以檢查CPU核心使用情況,線程使用情況和線程等待情況等等。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/08/12/729fc080ace1f81fbcc6cca6054b81e0.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com