Browse Source

Add performance test for retrieving image

onevcat 10 years ago
parent
commit
9a3a9a0754
1 changed files with 21 additions and 0 deletions
  1. 21 0
      KingfisherTests/ImageCacheTests.swift

+ 21 - 0
KingfisherTests/ImageCacheTests.swift

@@ -154,6 +154,27 @@ class ImageCacheTests: XCTestCase {
         waitForExpectationsWithTimeout(1, handler: nil)
     }
     
+    func testRetrivingImagePerformance() {
+
+        let expectation = self.expectationWithDescription("wait for retriving image")
+        
+        self.cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in
+            
+            // Base line is ~0.25 in iPhone 6 simulator.
+            // (Baseline setting for block measure is not available for using in Xcode 6.3 & Swift 1.2)
+            self.measureBlock({ () -> Void in
+                for _ in 1 ..< 1000 {
+                    self.cache.retrieveImageInDiskCacheForKey(testKeys[0])
+                }
+            })
+        
+            expectation.fulfill()
+            
+        }
+        
+        self.waitForExpectationsWithTimeout(5, handler: nil)
+    }
+
     // MARK: - Helper
     func storeMultipleImages(completionHandler:()->()) {