Apple Open Sources Swift Benchmark Suite

by

swift.pngApple today announced that its Swift benchmark suite is open source, just over two months after making its Swift programming language open sourced as promised at the 2015 Worldwide Developers Conference.

Apple's Swift benchmarking suite is designed to track Swift performance with 75 benchmarks that cover multiple important Swift workloads, libraries with commonly needed benchmarking functions, drivers for running benchmarks and displaying performance metrics, and a utility for comparing benchmark metrics across multiple versions of Swift. The Swift benchmark suite is available on GitHub.

Introduced in 2014 and launched alongside iOS 8 and OS X, Swift is Apple's programming language built for iOS, OS X, watchOS, and tvOS, designed to work with Cocoa and Cocoa Touch frameworks along with Objective-C while also being widely accessible. In 2015, Apple debuted Swift 2 with new features like advanced error handling and syntax enhancements.

Top Rated Comments

(View all)
Avatar
59 months ago

From what I heard the only app that's written in Swift by Apple is the calculator app. So, I think it'll be decade before it really catches on like you said.

Well, you don't rewrite an app because there's a new language, Maybe calc was chosen as a proof of concept.

At my company, all apps are obj-c and will remain so for the foreseeable future.

Maybe new UI could be written in swift, for the hell of it. Maybe it's like what they say about going black... :-)

Keep in mind that this C++ guy accepted to move a legacy app to ARC about a year or so ago. (I don't regret that at all now!)
Score: 2 Votes (Like | Disagree)
Avatar
59 months ago

Well, you don't rewrite an app because there's a new language, Maybe calc was chosen as a proof of concept.

At my company, all apps are obj-c and will remain so for the foreseeable future.

Maybe new UI could be written in swift, for the hell of it. Maybe it's like what they say about going black... :)

Keep in mind that this C++ guy accepted to move a legacy app to ARC about a year or so ago. (I don't regret that at all now!)

Well from what I hear, coding with Swift takes considerably less time, and developers have nothing but good things to say about it.
Score: 1 Votes (Like | Disagree)
Avatar
59 months ago
All of our new code is Swift. Now we have a huge app - so its going to be a long time before we are anywhere close to most of it being Swift. But I've been doing all new code since about 6 months ago in Swift, and my other engineers only the last 2-3 months. Swift makes so many things better, we'd love to sit down and convert existing code to Swift…but there is little point unless we hit upon a good reason.
Score: 1 Votes (Like | Disagree)
Avatar
59 months ago

It's not as bad as with Java. For example there are nice structs, which Java doesn't have IIRC. But I don't like the casting required everywhere:

<snip>

So all these good Swift things kinda get in the way and I don't like how the code looks, either.

These are all signs that you are trying to bend the language to a particular way of doing things rather than actually doing things in the language. A couple things to point out in the code you wrote:
- Using C-style enumeration rather than the range enumerator, and not specifying a type for "i", which would help with the casting behavior. Swift defaults to the default int size of the platform if you don't.
- Using a buffer rather than just letting the array size itself appropriately to fit the content (pre-sizing is a minor optimization).
- Should be using Character or UnicodeScalar instead of UInt8. Swift doesn't assume that you are in ASCII-land, which is part of your trouble. Since you are writing code to fill a character buffer, but not actually using characters, but ASCII.
- Instead of enumerating the array, you create an unsafe pointer and do another C-style loop. This is the worst way to iterate through an array you already have.
- Why even use a buffer like this when a String can be sliced up and converted into the UnicodeScalars if you need the underlying value. You can also create slices of arrays if you want to only pass around a piece of an array (circular buffers for example).
- While UnicodeScalar and Character are somewhat incomplete if you need the ability to do math on the underlying value, you can always add them as operators to make the code doing the manipulation cleaner rather than keeping values that don't represent what you are actually working with.

For grins, I wrote up a version of the sample code you wrote using UnicodeScalar. Either way it is a bit contrived as the real solution will depend on how these things interact with the rest of the program. It also avoids extending array (which it should) for printing the hex values, which does require a few steps to get it right.


func +<T:UnsignedIntegerType>(lhs: UnicodeScalar, rhs: T) -> UnicodeScalar {
return UnicodeScalar(lhs.value + UInt32(rhs.toUIntMax()))
}

func printArrayAsHexValues(buffer: [UnicodeScalar]) {
for element in buffer {
print(String(format: "%@ = 0x%X", String(element), element.value))
}
}

var startChar = UnicodeScalar(65)
var characterBuffer:[UnicodeScalar] = []
for offset : UInt32 in 0...9 { // Range is inclusive
characterBuffer.append(startChar + offset)
}

printArrayAsHexValues(characterBuffer)


This code has the advantage of being easier to read, clearer behavior, and the customizations are actually reusable. Again, this isn't really code I'd actually write in Swift in practice, since I'd either be using an integer buffer for raw data (possibly an NSMutableData if on Apple platforms), and a string for a character buffer.

One of the other issues with Swift is that the standard library is woefully tiny. You basically have to marshal out to a framework, and AppKit/UIKit/GCD are first class citizens, while the POSIX APIs are very much not.

But the code you wrote suggests someone with a strong C background, possibly spending a lot of time in low level code, and not having spent much time with Obj-C, Python, C# or other modern languages used in app and tool development.

Honestly, swift is something you need to dig into, and unfortunately, if you are doing so off an Apple platform, the frameworks just aren't there to support a rich experience. And even if you are on an Apple platform, AppKit and UIKit prevent certain features of Swift from being used to their full potential because you can get more functional programming styles done in Swift, but then things like CoreData rip you back into the world of reference types of multi threading hell that results.

As for the comment of the GP that comments about efficient coding techniques, those are the same techniques that create crashes, security holes and other fun. All for the opportunity to maybe outsmart the compiler, when in many cases, bugs I've run into are because someone tried to outsmart the compiler, and got bit later because it forced the compiler into undefined parts of the C spec, or it actually prevented the optimizer from finding an even faster optimization because mucking with the pointers turned the whole process into something opaque.
Score: 1 Votes (Like | Disagree)
Avatar
59 months ago

2) mixing languages in an existing project makes it too complex

What problems are you encountering with this?
Mixing ObjC/Swift in the same project works great even with my huge decade+ old OSX code bases!
Score: 1 Votes (Like | Disagree)
Avatar
59 months ago

Introduced in 2014 ('https://www.macrumors.com/2014/06/02/apple-ios-8-sdk/') and launched alongside iOS 8 and OS X, Swift is Apple's programming language built for iOS, OS X, watchOS, and tvOS, designed to work with Cocoa and Cocoa Touch frameworks along with Objective-C while also being widely accessible. In 2015, Apple debuted Swift 2 ('https://www.macrumors.com/2015/06/08/apple-announces-swift-2-open-source/') with new features like advanced error handling and syntax enhancements.

Article Link: Apple Open Sources Swift Benchmark Suite ('https://www.macrumors.com/2016/02/08/apple-open-sources-swift-benchmark-suite/')

I'd like to see an adoption graph of Swift since its release. For example, how many app submitted to the store are written in Swift vs. Objective-C on a month-to-month trend. I somehow feel an Apple employee is reading this with that exact graph in an other window on their desktop they wish they could release.

First, they announce it out of the blue at WWDC 2014. Then real quite the first year with many complaining about a buggy compiler. Then WWDC 2015, it goes open source to a rumored very soft acceptance. Now the benchmark tools are open source.

I'm still running into a lot of firms with a "No Swift" development policy because:

1) many say it is an immature language
2) mixing languages in an existing project makes it too complex
3) a catch-22 of few with Swift experience but few willing to commission projects in the language

This reminds me of the early Java days in the 90's where it took almost ten years for it to really take off in the industry.

One place I'm seeing Swift adopted well is in Frameworks development where many new APIs are written in Swift. Then these Frameworks integrate into apps written in Swift or Objective-C.
Score: 1 Votes (Like | Disagree)

Top Stories

Apple Takes Legal Action Against Small Company With Pear Logo

Saturday August 8, 2020 11:09 am PDT by
Apple is taking legal action against the developers of the app "Prepear" due to its logo, according to iPhone in Canada. Prepear is an app that helps users discover recipes, plan meals, make lists, and arrange grocery deliveries. The app is a spinoff of "Super Healthy Kids," and the founders claim that they are facing litigation from Apple. Apple reportedly takes issue with Prepear's logo, ...

Kuo: Global iPhone Shipments Could Decline Up to 30% If Apple Forced to Remove WeChat From App Store [Updated x2]

Sunday August 9, 2020 10:17 pm PDT by
In a worst-case scenario, Apple's annual global iPhone shipments could decline by 25–30% if it is forced to remove WeChat from its App Stores around the world, according to a new research note from analyst Ming-Chi Kuo viewed by MacRumors. The removal could occur due to a recent executive order aiming to ban U.S. transactions with WeChat and its parent company Tencent. Kuo lays out...

Google Maps Debuts New Apple Watch App and CarPlay Features

Monday August 10, 2020 9:16 am PDT by
Google today announced the launch of several features for Google Maps on Apple products, including new CarPlay functionality and a new Google Maps app that works on Apple Watch. The new Google Maps app for Apple Watch works similarly to the iOS app, allowing Apple Watch owners to get directions for a car, bike, public transit, or on foot. The app supports estimated arrival times and...

Foxconn Reportedly Begins Seasonal Hiring Spree for iPhone 12 Production

Monday August 10, 2020 7:03 am PDT by
Apple's largest manufacturing partner Foxconn has begun its seasonal hiring spree to assist with iPhone 12 production, offering employees who recruit qualified applicants up to a 9,000 yuan bonus, according to Chinese media reports. As usual, Foxconn needs as many hands on deck as possible at its factory in Zhengzhou, China to assist with mass production of the upcoming iPhones. Apple is...

Apple May Release 4G-Only iPhone 12 in Early 2021

Tuesday August 11, 2020 5:28 am PDT by
In a research note shared by Business Insider, Wedbush Securities analysts said that Apple may release a cheaper iPhone 12 in early 2021 with no 5G connectivity. Wedbush initially believed Apple would launch a mix of 4G and 5G iPhone 12 models this fall. Following re-examination of Asian supply chains, analysts Daniel Ives, Strecker Backe, and Ahmad Khalil revised the predictions,...

2020 iMac Teardown Reveals Internal Changes and Similarities

Saturday August 8, 2020 12:44 pm PDT by
A teardown video, shared by OWC, reveals the internal changes in the new 2020 27-inch iMac. The 2020 27-inch iMac was announced earlier this week with 10th-generation Intel Core processors, AMD Radeon Pro 5000 series graphics, up to 128GB of RAM, up to 8TB of storage, a 1080p front-facing FaceTime camera, a True Tone display with a nano-texture glass option, higher fidelity speakers, and...

Apple Believes This German Cycling Path Logo Infringes on Its Own Logo

Wednesday May 1, 2019 9:51 am PDT by
Apple recently objected to the logo of a new German cycling path in an appeal filed with the German Patent and Trademark Office, according to German outlets General-Anzeiger Bonn and Westdeutscher Rundfunk. Apple reportedly takes issue with the logo's green leaf and supposed "bitten" right side, attributes the company believes are too similar to its own logo. The logo, registered with the ...

Apple Seeds First Public Beta of watchOS 7 to Public Beta Testers

Monday August 10, 2020 10:33 am PDT by
Apple today seeded the first public beta of an upcoming watchOS 7 update to public beta testers, one week after seeding the fourth beta to developers and a month and a half after the Worldwide Developers Conference. The update can be downloaded after installing the proper profile from Apple's Public Beta website. watchOS 7 should not be installed on a primary device as it is still an early...

Apple Watch Likely to Adopt MicroLED Display Technology in 3-4 Years

Monday August 10, 2020 2:55 am PDT by
This year's Apple Watch Series 6 is expected to feature an OLED screen like previous models, but a future model is likely to be the first Apple product to adopt MicroLED display technology, albeit not for another three to four years. That's the main takeaway reading between the lines of comments made by the chairman of Epistar, Taiwan's top LED producer, which is reportedly working on a...

Apple Seeds iOS 14 and iPadOS 14 Public Beta 4 to Testers

Thursday August 6, 2020 10:05 am PDT by
Apple today seeded new public betas of upcoming iOS 14 and iPadOS 14 updates to its public beta testing group. Today's software releases, which Apple labels as fourth betas to keep them in line with developer betas, are actually the third betas that Apple has provided and they come two weeks after the prior beta releases. Public beta testers who have signed up for Apple's beta testing...