1

有没有人有任何提示或库链接来帮助在 AS3 中对应用程序进行基准测试?我(希望)正在寻找与Benchmark.js类似的东西,但要寻找 Flash 和 AIR。欢迎任何建议。

4

5 回答 5

4

我经常使用的一种快速测量代码执行时间的方法是:

var start_time:int = getTimer();

someComplexCode();

trace("execution time: ", getTimer()-start_time);

这将为您提供以毫秒为单位的数字。

于 2013-04-02T14:40:24.890 回答
3

这并不是真正的基准测试,但Adob​​e Scout是一个出色的分析器/性能测试器。从 Web 的 SWF 到 Adob​​e AIR 应用程序再到移动 AIR 应用程序,我一直在使用它。

于 2013-04-02T17:29:49.093 回答
1

您可以尝试使用这个:性能测试另外,我在这里找到了一些很好的信息。

于 2013-04-02T12:30:36.497 回答
0

Building on lostPixels' answer, I created a function that is similar to Python's timeit() function. The function repeats the callback function for the number of iterations specified and returns the fastest execution time. The default is 1,000,000 iterations.

The following Test program ran in about 391ms on my machine. Without the trace() statements, the test takes less than 1ms to execute.

TimeIt.as

package {
  public class TimeIt {
    import flash.utils.getTimer;

    public static function timeIt(callback:Function, maxIterations:uint=1000000):int {
      var start_time:int, duration:int, fastest_time:int = int.MAX_VALUE;
      for (var i:int = 0; i < maxIterations; i++) {
        start_time = getTimer();
        callback();
        duration = getTimer() - start_time;
        if (duration < fastest_time) fastest_time = duration
      }
      return fastest_time;
    }
  }
}

Test.as

package {
  public class Test {
    public function Test() {
      trace('Fastest Time:', TimeIt.timeIt(test, 10),'ms');
    }

    public function test():void {
      var k:int, m:int = 100;
      for (var i:int = 0; i < m; i++) {
        for (var j:int = 0; j < m; j++) {
          k = m * i + j;
          trace(k);
        }
      }
    }
  }
}

Main.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" 
    initialize="init(event)">
    <fx:Script>
        <![CDATA[
            protected function init(event:Event):void {
                new Test();
            }
        ]]>
    </fx:Script>
</s:Application>
于 2013-04-03T01:20:18.520 回答
0

您可以很容易地设置基准测试方法:

function test(process:Function, repeat:int = 10):void
{
    var time:Number = getTimer();
    while(--repeat >= 0) process();
    trace(getTimer() - time);
}

像这样使用:

// See how long it takes to create 50,000 Sprites and
// add them to the DisplayList.
test(function()
{
    var sprite:Sprite = new Sprite();
    addChild(sprite);

}, 50000);
于 2013-04-03T00:54:57.987 回答