Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
md5: 472a6fc38d023d4100ea2188bc387c7d
Issue Description:
In the following code, the flatMap (used for compatibility with swift 4.0.3) performs much worse than the filter + map under a -O build.
flatMap
filter
map
-O
import Dispatch func benchmark<T>(_ function: () -> T) -> (T, Double) { let start = DispatchTime.now() let res = function() let end = DispatchTime.now() return (res, Double(end.uptimeNanoseconds - start.uptimeNanoseconds) / 1_000_000_000) } let base = 0..<1_000_000 let (fmRes, flatMapTime) = benchmark { base.lazy.flatMap({ $0 % 4 == 0 ? nil : $0 }).reduce(0, +) } let (mapRes, mapTime) = benchmark { base.lazy.filter({ $0 % 4 != 0 }).map({ $0 }).reduce(0, +) } print("Flat Map: \(fmRes), took \(flatMapTime)\n Map: \(mapRes), took \(mapTime)")
Output under swift 4.1 as far back as the 2017 October 25 snapshot (oldest I could find):
Flat Map: 375000000000, took 0.876876712 Map: 375000000000, took 0.002207212
Output under swift 4.0.3 release:
Flat Map: 375000000000, took 0.002158283 Map: 375000000000, took 0.002088703
The text was updated successfully, but these errors were encountered:
@swift-ci create
Sorry, something went wrong.
Fixed in #17885
eeckstein
No branches or pull requests
tellowkrinkle commentedJun 10, 2018
Additional Detail from JIRA
md5: 472a6fc38d023d4100ea2188bc387c7d
Issue Description:
In the following code, the
flatMap
(used for compatibility with swift 4.0.3) performs much worse than thefilter
+map
under a-O
build.Output under swift 4.1 as far back as the 2017 October 25 snapshot (oldest I could find):
Output under swift 4.0.3 release:
The text was updated successfully, but these errors were encountered: