Database Reference
In-Depth Information
Once the tests have finished running, Xcode will look like this:
Notice two new things:
1. There's a green checkmark next to testTotalEmployeesPerDepartment . That
means the test ran and passed.
2. There's a message on the right side with the amount of time the test took.
On my iPhone 4S test device used for the above screenshot, the test took 0.067
seconds to perform the totalEmployeesPerDepartment operation. These results
might seem good but there is still room for improvement.
Note: These screenshots where generated with an iPhone 4S. You might get
somewhat different test results, depending on your test device. Don't worry—
what's important is the change in time you'll see after you modify the project.
Changes to improve performance
The current implementation of totalEmployeesPerDepartment uses a fetch request to
iterate through all employee records. Remember the very first optimization in this
chapter, where you split out the full-size photo into a separate entity? There's a
similar issue here: Core Data loads the entire employee record, but all you really
need is a count of employees by department.
It would be more efficient to somehow group the records by department and just
get a count; you don't need the details like employee names and photo thumbnails!
Open DepartmentListViewController.swift and add the following code to the
class:
public func totalEmployeesPerDepartmentFast()
-> [[ String : String ]] {
//1
Search WWH ::




Custom Search