© 2006 - 2012 Hannes Wolfgang Moser

Update: Performance ActionScript 3

So, ActionScript 3 auch angetestet und eines muss ich sagen, das nächste Release, bzw. der Release des Flash Player 8.5 wird ein Meilenstein, die Flash Virtual Machine 2 hat bei meinem Benchmark und man muss hinzufügen, bei einem nicht optimierten Player einfache Funktionsaufrufe um das bis zu 4-fache schneller sind, im Schnitt ergab es bei mir das 3,5-fache und das ganze sieht in nackten Zahlen so aus. Continue reading



Performance : ActionScript 2 vs ActionScript 1

Da manche Programmierer und “ActionScript2 Doof Finder” immer noch meckern über die Java-ähnliche Codeentwicklung, habe ich natürlich immer ein paar Vorteile von AS2 auf Lager, eine davon war das AS2 mehr Performance bietet, da die doppelte Anzahl an Register verwendet werden können.

Das ganze habe ich getestet an einem simplen Funktionsaufruf, ActionScript 2 Variante mit Typdeklarierung, von der ich mir am meisten Vorteile erwartet habe, da nur der Anzahl an Speiche reserviert werden muss, der tatsächlich benötigt wird.

Folgende 2 Scripte wurden getestet.

Mit Typdekleration:

[as]// attributes
var o:Object;
// namespaces
_global.com = {};
_global.com.impossiblearts = {};
// o prototype declaration
o = _global.com.impossiblearts;
// prototypes
o.Circle = function(stack:MovieClip) {
// constructor
// attributes
var s:MovieClip = stack;
var m:MovieClip;

this.__x = null;
this.__y = null;

// add property
addProperty(“_x”, this.getX, this.setX);
addProperty(“_y”, this.getY, this.setY);

m = s.attachMovie(“c”, “c” + String(s.getNextHighestDepth()), s.getNextHighestDepth());

return m;
}
o = o.prototype;
// getter/setter x-position
o.setX = function(arg:Number):Void {
this.__x = arg;
}
o.getX = function():Number {
return this.__x;
}
o.setY = function(arg:Number):Void {
this.__y = arg;
}
o.getY = function():Number {
return this.__Y;
}
// stack init
var s:MovieClip = _root.createEmptyMovieClip(“stack_container”, 1);
// engine settings
var ts:Number = getTimer();

for(var i:Number = 0; i < 1000000; i++) {
new Circle(s);
}
trace("processing time: " + (getTimer() - ts));[/as]

Ohne Typdekleration:

[as]// attributes
var o;
// namespaces
_global.com = {};
_global.com.impossiblearts = {};
// o prototype declaration
o = _global.com.impossiblearts;
// prototypes
o.Circle = function(stack) {
// constructor
// attributes
var s = stack;
var m;

this.__x = null;
this.__y = null;

// add property
addProperty(“_x”, this.getX, this.setX);
addProperty(“_y”, this.getY, this.setY);

m = s.attachMovie(“c”, “c” + String(s.getNextHighestDepth()), s.getNextHighestDepth());

return m;
}
o = o.prototype;
// getter/setter x-position
o.setX = function(arg) {
this.__x = arg;
}
o.getX = function() {
return this.__x;
}
o.setY = function(arg) {
this.__y = arg;
}
o.getY = function() {
return this.__Y;
}
// stack init
var s = _root.createEmptyMovieClip(“stack_container”, 1);
// engine settings
var ts = getTimer();

for(var i = 0; i < 1000000; i++) {
new Circle(s);
}
trace(“processing time: ” + (getTimer() – ts));[/as]

Ergebniss der Mühe, AS1 ist exakt gleich schnell(langsam) wie AS2, egal o für AS2 kompiliert oder nicht. Da macht man sich doch Gedankgen, oder das Typmodell dann noch irgendeneinen Sinn macht, außer eventuell die zweifelhaft zuverlässigen Debuggermeldungen aus dem Flash-Ausgabe Fenster, falls ein Typ falsch deklariert wurde.
AS3 Sample folgt in Kürze, ist aber vom Konzept sowieso nicht vergleichbar, da eine andere VirtualMachine benutzt wird.



Call All Instances

Es gibt Tage da würde man sich gerne selbst loben, oder man ist einfach nur froh nach ein paar Stunden etwas gefunden zu haben, dass man bereits mit 17 besser programmiert hat.

Benötige für ein Flash-Projekt eine Funktion die mir alle Instanzen benachrichtigt, ohne das ich sie über eine For-Schleife aufrufen müsste, finds genial

  1. import mx.events.EventDispatcher;
  2. class CallAllInstances {
  3. private static var dispatcher:EventDispatcher = null;
  4. private static var instanceCount:Number = 0;
  5. private var id:Number;
  6. function CallAllInstances() {
  7. // initalize EventDispatcher
  8. if(dispatcher == null) {
  9. dispatcher = new EventDispatcher();
  10. }
  11. // register your instanceEvents
  12. dispatcher.addEventListener("firstEvent",this);
  13. dispatcher.addEventListener("secondEvent",this);
  14. // instances initalised
  15. instanceCount++;
  16. id = instanceCount;
  17. }
  18. public static function callInstanceEvent(event:String, __data:Object):Void {
  19. dispatcher.dispatchEvent({type:event, data:__data});
  20. }
  21. public function firstEvent():Void {
  22. trace("firstEvent: "+id);
  23. }
  24. public function secondEvent():Void {
  25. trace("secondEvent:"+id);
  26. }
  27. }

Seitenhieb auf AJAX:

Macht uns das einmal nach, he he




© 2006 - 2012 Hannes Wolfgang Moser