In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Easy Benchmark with StatsCollector

Get Adobe Flash player
by yonatan 08 Oct 2011
  • Forked from ton's Easy Benchmark
  • Diff: 37
  • Related works: 4
  • Talk

    yonatan at 09 Oct 2011 10:23
    results url: http://zozuar.org/wonderfl/benchmarks/results/gUVO.csv
    Hasufel at 13 Oct 2011 18:23
    interesting results, thx yonatan. Oddly bench executed on 13" display 1280*800, but thought second screen was the only one. I now know the power of KappaTech's i7 :)

    Tags

    Embed
// forked from ton's Easy Benchmark
/*
簡易ベンチマークです。
ランダムな速度で動くボールを毎フレームごとに100個ずつ追加していき、
直近10秒の平均fpsが30以下になった時点のボールの数をスコアとします。
スコアが出るまで少し時間がかかります。
ちょっと待ってね just a moment!
*/
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.getTimer;
	[SWF(frameRate=240)]
	public class EasyBenchmark extends Sprite {
		private const W:int = 465;
		private const H:int = 465;
		private const MAX_V:int = 10;
		private const MIN_V:int = 3;
		
		private var balls:/*Ball*/Array = [];
		private var frameRates:/*int*/Array = [];
		private var index:int = 0;
		private var ave:int = 120;
		
		private var ballCnt:int = 0;
		private var txtBallCnt:TextField;
		
		private var frameCnt:int = 0;
		private var txtFrameCnt:TextField;
		private var oldTimer:int;
		
		private var bmd:BitmapData;
		private var bmp:Bitmap;
		
		public function EasyBenchmark():void {	
			bmd = new BitmapData(W, H, false);
			bmp = new Bitmap(bmd);
			addChild(bmp);
			
			txtBallCnt = new TextField();
			txtBallCnt.autoSize = "left";
			txtBallCnt.background = true;
			addChild(txtBallCnt);
			
			txtFrameCnt = new TextField();
			txtFrameCnt.autoSize = "left";
			txtFrameCnt.background = true;
			txtFrameCnt.y = 30;
			addChild(txtFrameCnt);
			
			oldTimer = getTimer();			
			addEventListener(Event.ENTER_FRAME, update);
		}
		
		private function update(e:Event):void {
			updateFrame();
			if (ave <= 30) {
				removeEventListener(Event.ENTER_FRAME, update);
				complete();
				return;
			}
			
			for (var i:int = 0; i < 100; i++){
				var ball:Ball = new Ball(randomRange(MAX_V, MIN_V), randomRange(MAX_V, MIN_V));
				ball.x = Math.random() * W;
				ball.y = Math.random() * H;
				balls.push(ball);
				ballCnt++;
			}
			txtBallCnt.text = "score : " + ballCnt;
			
			bmd.fillRect(bmd.rect, 0xffffff);
			for each(ball in  balls) {
				ball.x += ball.vx;
				ball.y += ball.vy;
				bmd.setPixel(ball.x, ball.y, 0xff0000);
				if (ball.x <= 0 || ball.x >= W) {
					ball.vx *= -1;
				}
				if (ball.y <= 0 || ball.y >= H) {
					ball.vy *= -1;
				}
			}
		}
		
		private function complete():void{
            StatsCollectorLoader.init(stage, {score: ballCnt});
		}
		
		private function updateFrame():void {
			frameCnt++;
			if (getTimer() - oldTimer >= 1000) {
				frameRates[index] = frameCnt;
				index = ++index % 10;
				ave = average.apply(null, frameRates);
				txtFrameCnt.text = "fps : " + frameCnt + "/" + stage.frameRate + "\nave : " + ave;
				frameCnt = 0;
				oldTimer = getTimer();
			}			
		}
		
		private function average(... rest):Number {
			var sum:Number = 0;
			for each(var n:Number in rest) sum += n;
			return sum / rest.length;
		}
		
		private function randomRange(max:Number, min:Number):Number {
			return Math.random()*(max - min) + min;
		}
		
	}
	
}

class Ball {
	public var x:Number;
	public var y:Number;
	public var vx:Number;
	public var vy:Number;
	
	public function Ball(vx:Number, vy:Number) {
		this.vx = vx;
		this.vy = vy;
	}
}

import flash.display.*;
import flash.net.*;
import flash.system.*;
class StatsCollectorLoader
{
    private static const URL:String = "http://swf.wonderfl.net/swf/usercode/e/e1/e154/e154bcc18ae75cf6c70f29a108e6af3eba3055d6.swf";
    public static function init(stage:Stage, results:Object): void 
    {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener("complete", function(e:*):void { loader.content["init"](stage, results); });
        loader.load(new URLRequest(URL), new LoaderContext(true));
    }
}