ActionScript - 从代码中分析脚本的速度?
我正在尝试使用日期类和跟踪语句从代码中分析我的代码的速度。效果不太好。
package
{
import flash.display.Sprite;
public class Test extends Sprite
{
public function Test()
{
var now:Date = new Date();
var profileSpeedMark:Number = now.getMilliseconds();
var myArray:Array = new Array();
for (var i:Number = 0; i < 1000000; i++)
myArray.push(Math.random());
var profileSpeedResult:Number = now.getMilliseconds() - profileSpeedMark;
trace(profileSpeedResult);
}
}
}
这里的想法是能够比较不同的函数编码方式并确定哪一种更快。除非我使用的是一台超级慢的计算机,否则我不确定这是否可能,特别是对于非常短的函数。
i'm trying to cave-man-profile the speed of my code from code using the date class and trace statements. it's not working out so well.
package
{
import flash.display.Sprite;
public class Test extends Sprite
{
public function Test()
{
var now:Date = new Date();
var profileSpeedMark:Number = now.getMilliseconds();
var myArray:Array = new Array();
for (var i:Number = 0; i < 1000000; i++)
myArray.push(Math.random());
var profileSpeedResult:Number = now.getMilliseconds() - profileSpeedMark;
trace(profileSpeedResult);
}
}
}
the idea here is to be able to compare different ways of coding functions and determine which one is faster. unless i'm on a super slow computer i'm not sure if this is possible, especially for really short functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用flash.utils包中的getTimer()函数很方便。
Its convenient to use getTimer() function in the flash.utils package.
您在示例代码中执行操作的方式的问题在于
Date
类具有固定值 - 您将测试之前的时间与再次测试之前的时间进行比较。尝试在测试后实例化另一个 Date 对象并从中获取时间:The problem with the way you've done things in your example code is that the
Date
class has a fixed value -- you're comparing the time before the tests with the time before the tests again. Try instantiating another Date object after your tests and taking the time from that: