PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/performance-test/org/osflash/signals/RemovePerformance.as

http://github.com/robertpenner/as3-signals
ActionScript | 113 lines | 89 code | 17 blank | 7 comment | 4 complexity | cb0fedadc95c3d3cc4d9305b14de444a MD5 | raw file
  1/**
  2 * Created by IntelliJ IDEA.
  3 * User: joa
  4 * Date: 11/22/10
  5 * Time: 4:34 PM
  6 * To change this template use File | Settings | File Templates.
  7 */
  8package org.osflash.signals
  9{
 10	import flash.display.Sprite;
 11	import flash.events.Event;
 12	import flash.system.System;
 13	import flash.text.TextField;
 14	import flash.text.TextFieldAutoSize;
 15	import flash.text.TextFormat;
 16	import flash.utils.getTimer;
 17
 18	[SWF(width=800, height=600, frameRate=64, backgroundColor=0x333333)]
 19	public class RemovePerformance extends Sprite
 20	{
 21		private var _out0: TextField;
 22		private var _out1: TextField;
 23		private var _s: ISignal;
 24		private var _t0: int;
 25
 26		private var _f: int;
 27		private var _min:int;
 28		private var _max:int;
 29
 30		public function RemovePerformance()
 31		{
 32			_out0 = new TextField();
 33			_out0.defaultTextFormat = new TextFormat('arial', 24, 0xff00ff);
 34			_out0.autoSize = TextFieldAutoSize.LEFT;
 35			_out0.x = 0x20;
 36			_out0.y = 0x20;
 37
 38			_out1 = new TextField();
 39			_out1.defaultTextFormat = new TextFormat('arial', 24, 0xff00ff);
 40			_out1.autoSize = TextFieldAutoSize.LEFT;
 41			_out1.x = 0x200;
 42			_out1.y = 0x20;
 43
 44			_s = new Signal();
 45
 46			addChild(_out0);
 47			addChild(_out1);
 48
 49			addEventListener(Event.ENTER_FRAME, onEnterFrame);
 50		}
 51
 52		private function onEnterFrame(event: Event): void
 53		{
 54			var t1: int = getTimer();
 55			if((t1 - _t0) >= 1000) {
 56				_out0.text = _f+'fps\n'+(System.totalMemory >> 20)+'mb\n'+_min+'ms\n'+_max+'ms';
 57				_f = 0;
 58				_t0 = t1;
 59			}
 60
 61			_f++;
 62			var n: int = 5000/4;
 63			var m0: int = getTimer();
 64			while(--n != 0) {
 65				_s.dispatch();
 66				_s.add(l0);//2**(4-1)=8
 67				_s.add(l1);
 68				_s.add(l2);
 69				_s.add(l3);
 70				_s.add(l4);
 71				_s.add(l5);
 72				_s.add(l6);
 73				_s.add(l7);
 74			}
 75			var dt: int = (getTimer() - m0);
 76			if(dt < _min) _min = dt;
 77			if(dt > _max) _max = dt;
 78			_out1.text = dt+'ms';
 79		}
 80
 81		private function l0(): void {
 82			_s.remove(l0);
 83		}
 84
 85		private function l1(): void {
 86			_s.remove(l1);
 87		}
 88
 89		private function l2(): void {
 90			_s.remove(l2);
 91		}
 92
 93		private function l3(): void {
 94			_s.remove(l3);
 95		}
 96
 97		private function l4(): void {
 98			_s.remove(l4);
 99		}
100
101		private function l5(): void {
102			_s.remove(l5);
103		}
104
105		private function l6(): void {
106			_s.remove(l6);
107		}
108
109		private function l7(): void {
110			_s.remove(l7);
111		}
112	}
113}