[swift-users] Performance critical code in Swift

Maury Markowitz maury.markowitz at gmail.com
Sun Oct 2 08:52:27 CDT 2016


> On Oct 1, 2016, at 4:50 PM, Игорь Никитин via swift-users <swift-users at swift.org> wrote:
> 
> For such of tasks C (or maybe C++) is a good choice. But how can Swift do this as fast as C?
> Of course I need to use low level C I/O api, but there are another things that I need to know?

All things considered, the choice of language *should* have minor impact on the outcome here - IO should be orders of magnitude slower than the processing. Of course, we all know examples where this is not the case, especially when you combine it with libraries like Cocoa that may or may not be very well optimized for IO.

That said, it seems like your data is simple enough that I'd suggest "just do it", and make a program that writes and then reads a million rows to a text file using Cocoa's primitives. Pure C with prinf/scanf will almost certainly be faster, but I'm also curious to know how much.

On a broader note, I have yet to see a true modern replacement for SQLite on the embedded side. There are any number of lightweight document stores, but they either have performance worse than SQLite, or are not really suitable for embedded use. I've seen a number of online solutions, and perhaps that is the right way to go these days. Anyone here used an online document store for largish data in Swift?


More information about the swift-users mailing list