Avatar
func testMultiplyPixel() { var rgba = [Double](repeating: 1, count: 4) let scalar: Double = 0.99 measure { // 0.108sec for _ in 0..<1000000 { rgba.withUnsafeMutableBufferPointer { var p = $0.baseAddress! for _ in 0..<$0.count { p.pointee *= scalar p += 1 } } } } } func testMultiplyPixel3() { var rgb = [Double](repeating: 1, count: 3) let scalar: Double = 0.99 measure { // 0.141sec for _ in 0..<1000000 { rgb.withUnsafeMutableBufferPointer { var p = $0.baseAddress! for _ in 0..<$0.count { p.pointee *= scalar p += 1 } } } } } 要素4つのほうが3つより早いという直感に反する結果に……