Skip to content

Instantly share code, notes, and snippets.

@b3ll
Created April 18, 2020 18:44
Show Gist options
  • Save b3ll/e8bfd98a12d69a67850b9c651ffcd104 to your computer and use it in GitHub Desktop.
Save b3ll/e8bfd98a12d69a67850b9c651ffcd104 to your computer and use it in GitHub Desktop.
Accelerate is p fast
import Accelerate
import XCTest
@testable import accelerateperftest
class AcceleratePerfTests: XCTestCase {
let values = Array<Float>(repeating: 0.25, count: 5000000)
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testMap() throws {
self.measure {
let newValues = values.map { (value) -> Float in
return value * 40.0
}
}
}
func testFor() throws {
self.measure {
var newValues = Array<Float>(values)
for i in 0..<newValues.count {
newValues[i] = values[i] * 40.0
}
}
}
func testAccelerate() throws {
self.measure {
var newValues = Array<Float>(values)
var mul = Float(40.0)
vDSP_vsmul(values, 1, &mul, &newValues, 1, vDSP_Length(values.count))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment