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 Shape

簡易ベンチマークShapeバージョンです。
ランダムな速度で動くボールを毎フレームごとに10個ずつ追加していき、
直近10秒の平均fpsが10以下になった時点のボールの数をスコアとします。
スコアが出るまで少し時間がかかります。
ちょっと待ってね just a moment!
Get Adobe Flash player
by ton 05 Oct 2011
  • Forked from ton's Easy Benchmark
  • Diff: 34
  • Related works: 4
  • Talk

    ton at 05 Oct 2011 03:37
    FP11.0.1.152 Win7x64 i7 860 chrome14 SCORE : 21320 MacOSX10.7 i5 2.3GHz safari5.1 SCORE : 18930
    yonatan at 05 Oct 2011 04:05
    FP 11,0,1,152 (64-bit), Linux, Intel Q9300 @ 2.5GHz, firefox 3.6, SCORE: 13510
    IPFix at 05 Oct 2011 04:07
    FP 11.0.0.58 Windows7 32bits, i5 @2.2Ghz, chrome 14 . SCORE : 15760
    djankey at 05 Oct 2011 06:17
    FP 11.0.1.152, Windows7 32bit, Core2Duo 2.4GHz, Chrome 14 > SCORE: 11820
    djankey at 05 Oct 2011 06:30
    FP 11.0.1.152, Android 2.3.4, Samsung Galaxy S, Opera Mobile > SCORE: 2250
    makc3d at 05 Oct 2011 14:11
    2660 on hp mini netbook + fp11 debugger
    keim_at_Si at 05 Oct 2011 18:27
    2750 (Atom Z520 with FP11)
    ton at 28 Jun 2012 15:52
    FP 11.3.31.109 Linux Mint 13 64bit Corei7 2700k Google Chrome 20 SCORE : 31230
    makc3d at 28 Jun 2012 19:54
    10190 FP 11.3.300.257, 2.93GHz Intel Core2Duo, 4GB 1067MHz DDR3, MBP circa 2009
    Hasufel at 28 Jun 2012 20:42
    11400 FF 14.0 FP 11.3.300.257 2.4Ghz Core2Duo, 8GB 1067Mhz DDR3, MBP circa 2010
    Hasufel at 20 Aug 2012 07:24
    23340 FF 14.0 FP 11.3.300.271 i7@2.9Ghz, 8GB 1600Mhz DDR3, MBP circa 2012

    Tags

    Embed
/*
簡易ベンチマークShapeバージョンです。
ランダムな速度で動くボールを毎フレームごとに10個ずつ追加していき、
直近10秒の平均fpsが10以下になった時点のボールの数をスコアとします。
スコアが出るまで少し時間がかかります。
ちょっと待ってね just a moment!
*/
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
    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=60)]
    public class EasyBenchmark extends Sprite {
        private const W:int = 465;
        private const H:int = 465;
		
		private const LIMIT:int = 10;
		
		private const BALLS:int = 10;
		
        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 canvas:Sprite;
        
        public function EasyBenchmark():void {    
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			canvas = new Sprite();
			addChild(canvas);
			
            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 <= LIMIT) {
                removeEventListener(Event.ENTER_FRAME, update);
                complete();
                return;
            }
            
            for (var i:int = 0; i < BALLS; 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++;
				canvas.addChild(ball);
            }
            txtBallCnt.text = "score : " + ballCnt;
            
            for each(ball in  balls) {
                ball.x += ball.vx;
                ball.y += ball.vy;
                if (ball.x <= 0 || ball.x >= W) {
                    ball.vx *= -1;
                }
                if (ball.y <= 0 || ball.y >= H) {
                    ball.vy *= -1;
                }
            }
        }
        
        private function complete():void{
            var tf:TextField = new TextField();
            tf.autoSize = "left";
            tf.text = "YOUR SCORE : " + ballCnt;
            tf.scaleX = tf.scaleY = 3;
            tf.x = W / 2 - tf.width / 2;
            tf.y = H / 2 - tf.height;
            addChild(tf);
            
            var button:TextField = new TextField();
            button.background = true;
            button.backgroundColor = 0xcccccc;
            button.autoSize = "left";
            button.selectable = false;
            button.text = "twitterに投稿";
            button.scaleX = button.scaleY = 2;
            button.x = W / 2 - button.width / 2;
            button.y = H / 2;
            button.addEventListener(MouseEvent.CLICK, function():void {
                navigateToURL(new URLRequest("http://twitter.com/?status=Easy Benchmark with Shape SCORE : "+ballCnt+" http://wonderfl.net/c/rFdY %23wonderfl"));
            });
            addChild(button);
            
        }
        
        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;
        }
        
    }
    
}
import flash.display.Shape;

class Ball extends Shape{
    public var vx:Number;
    public var vy:Number;
    
    public function Ball(vx:Number, vy:Number) {
        this.vx = vx;
        this.vy = vy;
		
		this.graphics.beginFill(Math.random() * 0xffffff, 0.5);
		this.graphics.drawCircle(0, 0, 2);
		this.graphics.endFill();
		
    }
}