CoreImage - 为什么执行时间不一致?

时间:2018-01-23 01:40:49

标签: ios iphone image core-graphics core-image

这是使用4个框架进行无操作图像处理的代码 - UIKitCoreGraphicsImage I/OCoreImage

DispatchQueue.main.async {
    var image: CGImage!
    measure("IMG IO") {
        image = self.imageIONoOp().cgImage!
        print("io: \(image.width)x\(image.height)")
    }
    measure("==== save IO") { self.save(image: image) }
}

DispatchQueue.main.async {
    var image: CGImage!
    measure("UI") {
        image = self.uiNoOp().cgImage!
        print("ui: \(image.width)x\(image.height)")
    }
    measure("==== save UI") { self.save(image: image) }
}

DispatchQueue.main.async {
    var image: CGImage!
    measure("CG") {
        image = self.cgNoOp().cgImage!
        print("cg: \(image.width)x\(image.height)")
    }
    measure("==== save CG") { self.save(image: image) }
}

DispatchQueue.main.async {
    var image: CGImage!
    measure("CIFilter") {
        let f = NoOpCIFilter()
        f.inputImage = CIImage(contentsOf: imgUrl)
        image = context.createCGImage(f.outputImage!, from: f.outputImage!.extent)!
        print("ci: \(image.width)x\(image.height)")
    }
    measure("==== save CI") { self.save(image: image) }
}

self.save(image: image)使用CGImage

将提供的Image I/O写入磁盘

该设备是iPhone 6 plus。

在3000x2000图像上运行时,我得到了这些:

io: 3000x2000
Measuring IMG IO: 115.519 milliseconds
saved 1.17mb
Measuring ==== save IO: 125.971 milliseconds

ui: 3000x2000
Measuring UI: 81.506 milliseconds
saved 1.17mb
Measuring ==== save UI: 110.822 milliseconds

cg: 3000x2000
Measuring CG: 66.13 milliseconds
saved 1.17mb
Measuring ==== save CG: 114.275 milliseconds

ci: 3000x2000
Measuring CIFilter: 100.614 milliseconds
saved 1.16mb
Measuring ==== save CI: 105.824 milliseconds

另一方面,当在10800x5400图像上运行代码时,我得到了这些:

io: 10800x5400
Measuring IMG IO: 1096.692 milliseconds
saved 21.11mb
Measuring ==== save IO: 1436.763 milliseconds

ui: 10800x5400
Measuring UI: 989.841 milliseconds
saved 21.11mb
Measuring ==== save UI: 1388.421 milliseconds

cg: 10800x5400
Measuring CG: 808.23 milliseconds
saved 21.11mb
Measuring ==== save CG: 1606.096 milliseconds

ci: 10800x5400
Measuring CIFilter: 29.509 milliseconds
saved 21.04mb
Measuring ==== save CI: 3160.284 milliseconds

问题:

  • 为什么较大的图像CIFilter操作比较小的图像花费的时间少?
  • 为什么在较大的图像上CIFilter之后保存操作需要两倍的预期时间?

0 个答案:

没有答案