Reputation: 8381
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
?
Upvotes: 3
Views: 1372
Reputation: 1976
There are methods for measuring performance in XCTestCase
: measure and measureMetrics.
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.
The Xcode template for Unit Test Case files has one performance test method example at the bottom:
class CoreDataTestTests: XCTestCase {
func testPerformanceExample() {
self.measure {
// Put the code you want to measure the time of here.
}
}
}
Upvotes: 4
Reputation: 29896
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.
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
.
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.
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.
Upvotes: 2