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

forked from: CPU performance graph (2)

// forked from makc3d's forked from: CPU performance graph
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.utils.getTimer;
	/**
	 * Trying histogram...
	 * @author makc
	 */
	public class Foo extends Sprite {
		public var t:PerformanceTest = new PerformanceTest;
		public var r:Rectangle = new Rectangle (464, 0, 1, 465);
		public var bmp:Bitmap;
		public function Foo () {
			addChild (bmp = new Bitmap (new BitmapData (465, 465, true, 0)));
			t.addEventListener (Event.COMPLETE, cpu); t.run ();
		}
		/**
		 * Quick CPU performance test.
		 */
		public function cpu (e:Event):void {
			// sorry guys if it takes > 465 ms for you :(
			bmp.bitmapData.scroll ( -1, 0);
			r.y = 0;
			bmp.bitmapData.fillRect (r, 0);
			r.y = 465 - t.performance;
			bmp.bitmapData.fillRect (r, 0xFF00FF00);
			// test again
			t.run ();
		}
	}
}

import flash.display.BitmapData;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.clearInterval;
import flash.utils.getTimer;
import flash.utils.setInterval;
class PerformanceTest extends EventDispatcher {
	private var bd:BitmapData;
	private var id:uint;
	private var t_lim:int;
	private var t_min:int;
	private var t_sum:int;
	private function test ():void {
		var t:int = getTimer ();
		bd.histogram ();
		t = getTimer () - t;
		if (t < t_min) t_min = t;
		t_sum += t;
		if (t_sum > t_lim) {
			clearInterval (id);
			bd.dispose (); bd = null;
			dispatchEvent (new Event (Event.COMPLETE));
		}
	}
	public function run (time:uint = 1000, interval:uint = 100):void {
		t_lim = time; t_min = int.MAX_VALUE; t_sum = 0;
		bd = new BitmapData (2879, 2879, false, 0);
		id = setInterval (test, interval);
	}
	public function get performance ():uint { return t_min; }
}