Skip to content

Commit

Permalink
bugfix; update benchmark demo
Browse files Browse the repository at this point in the history
  • Loading branch information
传骑 committed Jul 5, 2021
1 parent dcf1f93 commit 5502901
Show file tree
Hide file tree
Showing 31 changed files with 1,440 additions and 997 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
114 changes: 58 additions & 56 deletions Benchmark/Benchmark/CacheIOViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Longinus
import YYWebImage
import SDWebImage
import Kingfisher
//import Kingfisher
import BBWebImage

class CacheIOViewController: ConsoleLabelViewController {
Expand Down Expand Up @@ -152,22 +152,23 @@ class CacheIOViewController: ConsoleLabelViewController {
var startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
SDWebImageManager.shared().imageCache?.store(item.1, imageData: nil, forKey: item.0, toDisk: false, completion: nil)
SDWebImageManager.shared.imageCache.store(item.1, imageData: nil, forKey: item.0, cacheType: SDImageCacheType.memory, completion: nil)
}
storeTime += CACurrentMediaTime() - startTime

startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
let image = SDWebImageManager.shared().imageCache?.imageFromMemoryCache(forKey: item.0)
let image = SDWebImageManager.shared.imageCache.queryImage(forKey: item.0, options: [], context: nil, cacheType: .memory, completion: nil)
if image == nil { LGPrint("💊 SDWebImage 取到图片为空") }
}
getTime += CACurrentMediaTime() - startTime

startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
SDWebImageManager.shared().imageCache?.removeImage(forKey: item.0, fromDisk: false, withCompletion: nil)
SDWebImageManager.shared.imageCache.removeImage(forKey: item.0, cacheType: .memory, completion: nil)
// SDWebImageManager.shared().imageCache?.removeImage(forKey: item.0, fromDisk: false, withCompletion: nil)
}
removeTime += CACurrentMediaTime() - startTime
}
Expand All @@ -180,25 +181,25 @@ class CacheIOViewController: ConsoleLabelViewController {
var startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
KingfisherManager.shared.cache.store(item.1,
forKey: item.0,
options: KingfisherParsedOptionsInfo([.cacheMemoryOnly]),
toDisk: false)
// KingfisherManager.shared.cache.store(item.1,
// forKey: item.0,
// options: KingfisherParsedOptionsInfo([.cacheMemoryOnly]),
// toDisk: false)
}
storeTime += CACurrentMediaTime() - startTime

startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
let image = KingfisherManager.shared.cache.retrieveImageInMemoryCache(forKey: item.0)
if image == nil { LGPrint("💊 Kingfisher 取到图片为空") }
// let image = KingfisherManager.shared.cache.retrieveImageInMemoryCache(forKey: item.0)
// if image == nil { LGPrint("💊 Kingfisher 取到图片为空") }
}
getTime += CACurrentMediaTime() - startTime

startTime = CACurrentMediaTime()
for item in allTestImages {
if exited { return }
KingfisherManager.shared.cache.removeImage(forKey: item.0, fromMemory: true, fromDisk: false, completionHandler: nil)
// KingfisherManager.shared.cache.removeImage(forKey: item.0, fromMemory: true, fromDisk: false, completionHandler: nil)
}
removeTime += CACurrentMediaTime() - startTime
}
Expand Down Expand Up @@ -389,14 +390,15 @@ class CacheIOViewController: ConsoleLabelViewController {
}
case .sdwebimage:
// SDWebImage
SDWebImageManager.shared().imageCache?.config.shouldCacheImagesInMemory = false
// SDWebImageManager.shared.imageCache.shouldca
// SDWebImageManager.shared().imageCache?.config.shouldCacheImagesInMemory = false
func testStore(_ completion: @escaping NoParamterBlock) {
print("\n\n\(type.name) 开始磁盘存储")
var i = allTestImages.count
for (index, item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
SDWebImageManager.shared().imageCache?.store(item.1, imageData: nil, forKey: item.0, toDisk: true) {
SDWebImageManager.shared.imageCache.store(item.1, imageData: nil, forKey: item.0, cacheType: .disk) {
print("\(type.name) 保存第\(index)张完成")
i -= 1
if i == 0 {
Expand All @@ -412,15 +414,15 @@ class CacheIOViewController: ConsoleLabelViewController {
for (index, item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
SDWebImageManager.shared().imageCache?.queryCacheOperation(forKey: item.0) { (image, _, _) in
print("\(type.name) 读取第\(index)张完成")
assert(image != nil)
i -= 1
if i == 0 {
getTime += CACurrentMediaTime() - startTime
completion()
}
}
// SDWebImageManager.shared.imageCache.queryCacheOperation(forKey: item.0) { (image, _, _) in
// print("\(type.name) 读取第\(index)张完成")
// assert(image != nil)
// i -= 1
// if i == 0 {
// getTime += CACurrentMediaTime() - startTime
// completion()
// }
// }
}
}
func testRemove(_ completion: @escaping NoParamterBlock) {
Expand All @@ -429,14 +431,14 @@ class CacheIOViewController: ConsoleLabelViewController {
for (index,item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
SDWebImageManager.shared().imageCache?.removeImage(forKey: item.0, fromDisk: true) {
print("\(type.name) 清理第\(index)张完成")
i -= 1
if i == 0 {
removeTime += CACurrentMediaTime() - startTime
completion()
}
}
// SDWebImageManager.shared().imageCache?.removeImage(forKey: item.0, fromDisk: true) {
// print("\(type.name) 清理第\(index)张完成")
// i -= 1
// if i == 0 {
// removeTime += CACurrentMediaTime() - startTime
// completion()
// }
// }
}
}
testStore {
Expand All @@ -454,15 +456,15 @@ class CacheIOViewController: ConsoleLabelViewController {
for (index, item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
KingfisherManager.shared.cache.store(item.1, original: nil, forKey: item.0, toDisk: true) {
print("\(type.name) 保存第\(index)张完成")
i -= 1
if i == 0 {
storeTime += CACurrentMediaTime() - startTime
KingfisherManager.shared.cache.clearMemoryCache()
completion()
}
}
// KingfisherManager.shared.cache.store(item.1, original: nil, forKey: item.0, toDisk: true) {
// print("\(type.name) 保存第\(index)张完成")
// i -= 1
// if i == 0 {
// storeTime += CACurrentMediaTime() - startTime
// KingfisherManager.shared.cache.clearMemoryCache()
// completion()
// }
// }
}
}
func testGet(_ completion: @escaping NoParamterBlock) {
Expand All @@ -471,15 +473,15 @@ class CacheIOViewController: ConsoleLabelViewController {
for (index, item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
KingfisherManager.shared.cache.retrieveImage(forKey: item.0, options: nil) { (image, _) in
print("\(type.name) 读取第\(index)张完成")
assert(image != nil)
i -= 1
if i == 0 {
getTime += CACurrentMediaTime() - startTime
completion()
}
}
// KingfisherManager.shared.cache.retrieveImage(forKey: item.0, options: nil) { (image, _) in
// print("\(type.name) 读取第\(index)张完成")
// assert(image != nil)
// i -= 1
// if i == 0 {
// getTime += CACurrentMediaTime() - startTime
// completion()
// }
// }
}
}
func testRemove(_ completion: @escaping NoParamterBlock) {
Expand All @@ -488,14 +490,14 @@ class CacheIOViewController: ConsoleLabelViewController {
for (index,item) in allTestImages.enumerated() {
if exited { return }
let startTime = CACurrentMediaTime()
KingfisherManager.shared.cache.removeImage(forKey: item.0, fromMemory: false, fromDisk: true) {
print("\(type.name) 清理第\(index)张完成")
i -= 1
if i == 0 {
removeTime += CACurrentMediaTime() - startTime
completion()
}
}
// KingfisherManager.shared.cache.removeImage(forKey: item.0, fromMemory: false, fromDisk: true) {
// print("\(type.name) 清理第\(index)张完成")
// i -= 1
// if i == 0 {
// removeTime += CACurrentMediaTime() - startTime
// completion()
// }
// }
}
}
testStore {
Expand Down
27 changes: 14 additions & 13 deletions Benchmark/Benchmark/ImageViewCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Longinus
import YYWebImage
import SDWebImage
import Kingfisher
//import Kingfisher
import BBWebImage

private let reuseIdentifier = "Cell"
Expand Down Expand Up @@ -161,13 +161,13 @@ class ImageWallCell: UICollectionViewCell {
return imageView
}()

private lazy var kfImageView: Kingfisher.AnimatedImageView = {
var imageView = Kingfisher.AnimatedImageView(frame: CGRect(origin: .zero, size: frame.size))
imageView.webImageType = .kingfisher
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
return imageView
}()
// private lazy var kfImageView: Kingfisher.AnimatedImageView = {
// var imageView = Kingfisher.AnimatedImageView(frame: CGRect(origin: .zero, size: frame.size))
// imageView.webImageType = .kingfisher
// imageView.contentMode = .scaleAspectFill
// imageView.clipsToBounds = true
// return imageView
// }()

private lazy var yyImageView: YYAnimatedImageView = {
var imageView = YYAnimatedImageView(frame: CGRect(origin: .zero, size: frame.size))
Expand All @@ -177,8 +177,8 @@ class ImageWallCell: UICollectionViewCell {
return imageView
}()

private lazy var sdImageView: FLAnimatedImageView = {
var imageView = FLAnimatedImageView(frame: CGRect(origin: .zero, size: frame.size))
private lazy var sdImageView: SDAnimatedImageView = {
var imageView = SDAnimatedImageView(frame: CGRect(origin: .zero, size: frame.size))
imageView.webImageType = .sdwebimage
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
Expand All @@ -198,15 +198,15 @@ class ImageWallCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(lgImageView)
contentView.addSubview(kfImageView)
// contentView.addSubview(kfImageView)
contentView.addSubview(yyImageView)
contentView.addSubview(sdImageView)
contentView.addSubview(bbImageView)
}

private func updateCurrentBenmarkType(type: WebImageType) {
if currentType == type { return }
let all = [lgImageView, kfImageView, yyImageView, sdImageView, bbImageView]
let all = [lgImageView,/* kfImageView,*/ yyImageView, sdImageView, bbImageView]
all.forEach { (imv) in
imv.isHidden = imv.webImageType != type
if !imv.isHidden {
Expand Down Expand Up @@ -235,7 +235,8 @@ class ImageWallCell: UICollectionViewCell {
backgroundColor: UIColor.gray)
lgImageView.lg.setImage(with: url, placeholder: placeholder, options: [.imageWithFadeAnimation, .showNetworkActivity], transformer: transformer, progress: nil, completion: nil)
case .kingfisher:
kfImageView.kf.setImage(with: url, placeholder: placeholder)
break
// kfImageView.kf.setImage(with: url, placeholder: placeholder)
case .sdwebimage:
sdImageView.sd_setImage(with: url, placeholderImage: placeholder, options: [], completed: nil)
case .yywebimage:
Expand Down
10 changes: 5 additions & 5 deletions Benchmark/Benchmark/MainTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Longinus
import YYWebImage
import SDWebImage
import Kingfisher
//import Kingfisher

class MainTableViewController: UITableViewController {

Expand Down Expand Up @@ -116,10 +116,10 @@ class MainTableViewController: UITableViewController {
if indexPath.row == menu.count {
loading.startAnimating()
LonginusManager.shared.imageCacher?.removeAll()
KingfisherManager.shared.cache.clearMemoryCache()
KingfisherManager.shared.cache.clearDiskCache()
SDWebImageManager.shared().imageCache?.clearMemory()
SDWebImageManager.shared().imageCache?.clearDisk(onCompletion: nil)
// KingfisherManager.shared.cache.clearMemoryCache()
// KingfisherManager.shared.cache.clearDiskCache()
SDWebImageManager.shared.imageCache.clear(with: .disk, completion: nil)
// SDWebImageManager.shared.imageCache.clearDisk(onCompletion: nil)
YYWebImageManager.shared().cache?.memoryCache.removeAllObjects()
YYWebImageManager.shared().cache?.diskCache.removeAllObjects()
loading.stopAnimating()
Expand Down
58 changes: 32 additions & 26 deletions Benchmark/Benchmark/WebImageLoadingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import Longinus
import YYWebImage
import SDWebImage
import Kingfisher
//import Kingfisher
import BBWebImage

class ConsoleLabelViewController: UIViewController {
Expand Down Expand Up @@ -76,8 +76,8 @@ class ConsoleLabelViewController: UIViewController {

private func cancelAll() {
LonginusManager.shared.cancelAll()
KingfisherManager.shared.downloader.cancelAll()
SDWebImageManager.shared().cancelAll()
// KingfisherManager.shared.downloader.cancelAll()
SDWebImageManager.shared.cancelAll()
YYWebImageManager.shared().queue?.cancelAllOperations()
BBWebImageManager.shared.cancelAll()
}
Expand All @@ -103,8 +103,7 @@ class WebImageLoadingViewController: ConsoleLabelViewController {
}

func runTestFromBeginning() {
SDWebImageManager.shared().imageCache?.clearMemory()
SDWebImageManager.shared().imageCache?.clearDisk(onCompletion: nil)
SDWebImageManager.shared.imageCache.clear(with: .all, completion: nil)
self.runTest(type: .longinus)
}

Expand Down Expand Up @@ -167,28 +166,35 @@ class WebImageLoadingViewController: ConsoleLabelViewController {
done(image: image, error: error)
}
case .kingfisher:
KingfisherManager.shared.retrieveImage(
with: url,
options: [.forceRefresh],
progressBlock: { (receivedSize, expectedSize) in
progress(receivedSize: Int(receivedSize), Int(expectedSize))
}, downloadTaskUpdated: nil) { (result) in
switch result {
case .success(let _result):
done(image: _result.image, error: nil)
case .failure(let _error):
done(image: nil, error: _error)
}
}
break
// KingfisherManager.shared.retrieveImage(
// with: url,
// options: [.forceRefresh],
// progressBlock: { (receivedSize, expectedSize) in
// progress(receivedSize: Int(receivedSize), Int(expectedSize))
// }, downloadTaskUpdated: nil) { (result) in
// switch result {
// case .success(let _result):
// done(image: _result.image, error: nil)
// case .failure(let _error):
// done(image: nil, error: _error)
// }
// }
case .sdwebimage:
SDWebImageManager.shared().loadImage(
with: url,
options: [.cacheMemoryOnly,.refreshCached],
progress: { (receivedSize, expectedSize, url) in
progress(receivedSize: Int(receivedSize), Int(expectedSize))
}) { (image, data, error, cacheType, finished, imageURL) in
done(image: image, error: error)
}
break
// SDWebImageManager.shared.loadImage(with: url, options: [.cacheMemoryOnly,.refreshCached], progress: { (receivedSize, expectedSize, url) in
// progress(receivedSize: Int(receivedSize), Int(expectedSize))
// }) { (image, data, error, cacheType, finished, imageURL) in
// done(image: image, error: error)
// }
// SDWebImageManager.shared.loadImage(
// with: url,
// options: [.cacheMemoryOnly,.refreshCached],
// progress: { (receivedSize, expectedSize, url) in
// progress(receivedSize: Int(receivedSize), Int(expectedSize))
// }) { (image, data, error, cacheType, finished, imageURL) in
// done(image: image, error: error)
// }
case .yywebimage:
YYWebImageManager.shared().requestImage(
with: url,
Expand Down
Loading

0 comments on commit 5502901

Please sign in to comment.