I see that playground execution speed is not reliable. For example with a code:
import UIKit
var count = 0;
let startTime = NSDate()
for i in 1...10000 {
count++
}
let endTime = NSDate()
let interval = endTime.timeIntervalSinceDate(startTime)
the value of interval
is about 2s, which is not reliable.
With the release of Swift 2.0 & XCode beta 7, is it possible to make swift playground code execute as fast as in iOS application?
As an aspiring app developer, you'll learn how Swift works with data and Swift playgrounds. You'll also adopt a protocol-oriented programming mindset as you work on developing apps on iPhone, Mac, or iPad. It takes about three to four learning hours to complete this course.
Select Product->Profile then select Time Profiler.
Swift Playgrounds is a revolutionary app for iPad and Mac that makes it fun to learn and experiment with Swift — a powerful programming language created by Apple and used by the pros to build today's most popular apps. Swift Playgrounds requires no coding knowledge, so it's perfect for students just starting out.
Swift Playgrounds is a beautiful looking environment to learn to code. It's a nice, modern, object-oriented language and I can learn concepts and conventions and put them to work later in Xcode. Children can choose step-by-step lessons and puzzles to build their coding knowledge and skills.
There's a workaround thanks to the Sources
folder of the Playground.
You can either use the menu to add external files:
New > Add files to sources
or go to menu:
View > Navigators > Show project navigator
and drop a .swift
file in the Sources
folder.
To be accessible, your code in this folder has to be public:
public class PlayGround {
public class func count() {
var count = 0
for i in 1...10000 {
count++
}
}
}
Then it's as usual in the Playground itself:
let startTime = NSDate()
PlayGround.count()
let endTime = NSDate()
let interval = endTime.timeIntervalSinceDate(startTime) // 0.0062
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With