Database Reference
In-Depth Information
This line of code uses the old and slow function to populate the department list
screen. Replace it by calling the function you just created:
items = totalEmployeesPerDepartmentFast ()
Now the app is populating the table view data source for the department list screen
with the faster NSExpression -backed fetch request.
Note: NSExpression is a powerful API, yet it is seldom used, at least directly.
When you create predicates with comparison operations, you may not know it,
but you're actually using expressions.
There are many pre-built statistical and arithmetical expressions available in
NSExpression, including average , sum , count , min , max , median , mode and stddev .
Consult the NSExpression documentation for a comprehensive overview.
Verify the changes
Now that you've made all the necessary changes to the project, it's once again time
to see if you've improved the app.
Open DepartmentListViewControllerTests.swift and add a new function to test
the totalEmployeesPerDepartmentFast function you just created.
func testTotalEmployeesPerDepartmentFast() {
measureMetrics([XCTPerformanceMetric_WallClockTime],
automaticallyStartMeasuring: false , forBlock:{
let departmentList = DepartmentListViewController()
departmentList.coreDataStack = CoreDataStack()
self .startMeasuring()
let items =
departmentList.totalEmployeesPerDepartmentFast()
self .stopMeasuring()
})
}
Like before, this test uses measureMetrics to see how long a particular function is
taking, in this case totalEmployeesPerDepartmentFast .
Now you need to run this test. From Xcode's menu bar, select Product and then
Test , or press U. This will build the app and run the tests.
Once the tests have finished running, Xcode will look like this:
Search WWH ::




Custom Search