How to make the runtime of a playground as fast as if we were launching an iOS application

I see that the performance speed of the playgrounds is not reliable. For example, with the code:

import UIKit var count = 0; let startTime = NSDate() for i in 1...10000 { count++ } let endTime = NSDate() let interval = endTime.timeIntervalSinceDate(startTime) 

enter image description here

interval value is about 2 s, which is not reliable. With the release of Swift 2.0 and Xcode beta 7, is it possible to execute a fast playground code as fast as in an iOS app?

+6
source share
1 answer

Workaround thanks to the Sources folder of the playground.

You can either use the menu to add external files:

Create> Add Files To Sources

or go to the menu:

View> Navigators> Show Project Navigator

and release the .swift file in the Sources folder.

To be accessible, your code in this folder must be publicly available:

 public class PlayGround { public class func count() { var count = 0 for i in 1...10000 { count++ } } } 

Then, as usual, on the playground itself:

 let startTime = NSDate() PlayGround.count() let endTime = NSDate() let interval = endTime.timeIntervalSinceDate(startTime) // 0.0062 
+7
source

Source: https://habr.com/ru/post/989220/


All Articles