Advertisement
Drakim

performance test alchemy

May 18th, 2012
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.Memory;
  2.  
  3.  
  4. /*
  5. Warning: Only use width and height sizes that are even with 2 otherwise write64 fails!
  6.  
  7. Observations:
  8. *write64 is pretty much twice as fast as write32, but since it doesn't return an int you can't work very effectively with it.
  9. *The debug player seriously slowed down my testing by a few tenfolds, in the release player performance should pretty much never be a problem.
  10. *writeLine's performance obvious changes depending on how wide the lines are. The performance is equal to write64 at 72px and write32 at 30px, which makes logical sense.
  11.  
  12. Todo:
  13. *Build my own custom writeLine that switches over to the most effective way depending on the length, and messure how this holds up to a regular writeLine in terms of what overhead I've added.
  14.  
  15. */
  16.  
  17. class Main {
  18.   static inline public var iterations:Int = 6500;
  19.   static inline public var width:Int = 50;
  20.   static inline public var height:Int = 50;
  21.   static inline public var testsize:Int = width*height*4;
  22.   static public function main() {
  23.     var mybytearray:flash.utils.ByteArray = new flash.utils.ByteArray();
  24.     mybytearray.length = width*height*4;
  25.     Memory.select(mybytearray);
  26.    
  27.     trace('Test: draw a '+width+'x'+height+' image '+iterations+' times');
  28.    
  29.     var start = getTime();
  30.     var i:Int = 0;
  31.     while(i <iterations) {
  32.       var a = 0;
  33.       while(a < testsize) {
  34.         Memory.setI32(a,Memory.getI32(a));
  35.         a+=4;
  36.       }
  37.      
  38.       ++i;
  39.     }
  40.     trace('write32: ' + (getTime()-start) + 'ms');
  41.    
  42.     var start = getTime();
  43.     var i:Int = 0;
  44.     while(i <iterations) {
  45.       var a = 0;
  46.       while(a < testsize) {
  47.         Memory.setDouble(a,Memory.getDouble(a));
  48.         a+=8;
  49.       }
  50.       ++i;
  51.     }
  52.     trace('write64: ' + (getTime()-start) + 'ms');
  53.  
  54.  
  55.     var start = getTime();
  56.     var i:Int = 0;
  57.     while(i <iterations) {
  58.       var a = 0;
  59.       while(a < testsize) {
  60.         mybytearray.position = a;
  61.         mybytearray.writeBytes(mybytearray,a,width*4);
  62.         a+=width*4;
  63.       }
  64.       ++i;
  65.     }
  66.     trace('writeLine: ' + (getTime()-start) + 'ms');
  67.   }
  68.  
  69.   static inline public function getTime():Int {
  70.     return Std.int(haxe.Timer.stamp()*1000);
  71.   }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement