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?
间隔的值约为2s,这是不可靠的。随着Swift 2.0和XCode beta 7的发布,是否可以像在iOS应用程序中那样快速地执行游戏代码?
1 个解决方案
#1
8
There's a workaround thanks to the Sources
folder of the Playground.
由于Playground的Sources文件夹,有一个解决方法。
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.
并在Sources文件夹中删除.swift文件。
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:
然后就像Playground本身一样:
let startTime = NSDate()
PlayGround.count()
let endTime = NSDate()
let interval = endTime.timeIntervalSinceDate(startTime) // 0.0062
#1
8
There's a workaround thanks to the Sources
folder of the Playground.
由于Playground的Sources文件夹,有一个解决方法。
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.
并在Sources文件夹中删除.swift文件。
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:
然后就像Playground本身一样:
let startTime = NSDate()
PlayGround.count()
let endTime = NSDate()
let interval = endTime.timeIntervalSinceDate(startTime) // 0.0062