Avatar
手元でちょっと試したら、 dot を自前なのやめて import simd したら倍くらいの速度になりました ❯ time ./test 20000000 -0.169075164 -0.169031665 ./test 20000000 2.19s user 0.00s system 99% cpu 2.200 total ❯ time ./test2 20000000 -0.169075164 -0.169031665 ./test2 20000000 1.20s user 0.00s system 99% cpu 1.207 total
7:07 AM
❯ diff test.swift test2.swift 1a2 > import simd 8,14c9,15 < func dot<V : SIMD>(_ a: V, _ b: V) -> V.Scalar where V.Scalar : FloatingPoint { < var total = V.Scalar(0) < for i in a.indices { < total = total.addingProduct(a[i], b[i]) < } < return total < } --- > // func dot<V : SIMD>(_ a: V, _ b: V) -> V.Scalar where V.Scalar : FloatingPoint { > // var total = V.Scalar(0) > // for i in a.indices { > // total = total.addingProduct(a[i], b[i]) > // } > // return total > // }