On Performant Arrays in Swift
jordansmith.io
jordansmith.io
var bytes = [UInt8](count: 16_737_732, reapeatedValue: 0)
This was slow enough to block my UI (spinning pizza) -- so I ran it on a background thead!. Turn on optimization and it took a more reasonable 0.0165 seconds. BTW, took C's memset only 0.00827 seconds on the same machine.I switched back to my beloved Objective-C for the app I was developing. Won't be using Swift for low-level image processing.
Can you write the app in Swift (if there are advantages to doing so) and then write the image processing routines/library in C?
Also I have been programming the Mac for a long time and I have a lot of mental investment in Objective-C.
OTOH, I do like the functional, strongly-type features of Swift, but like any higher level language I feel more removed from the machine. That's the price for abstraction.
I think it’s because that’s the style of Apple’s own (excellent) Swift Programming Language book.
I think it does look nicer than the traditional characters used in these kinds of things.
https://developer.apple.com/library/content/documentation/Sw... says the two are bridged, but doesn’t mention whether that is toll-free.
If that is toll-free, users of Array, just as users of NSArray, should be aware that indexing in them can be O(log n). See http://ridiculousfish.com/blog/posts/array.html
Honestly I never run into performance problems since the volume of data I work with is either really huge and done in a C or C++-based library or so small I would never think about array performance.
Good developers have battery empathy.