Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.Memory;
- /*
- Warning: Only use width and height sizes that are even with 2 otherwise write64 fails!
- Observations:
- *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.
- *The debug player seriously slowed down my testing by a few tenfolds, in the release player performance should pretty much never be a problem.
- *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.
- Todo:
- *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.
- */
- class Main {
- static inline public var iterations:Int = 6500;
- static inline public var width:Int = 50;
- static inline public var height:Int = 50;
- static inline public var testsize:Int = width*height*4;
- static public function main() {
- var mybytearray:flash.utils.ByteArray = new flash.utils.ByteArray();
- mybytearray.length = width*height*4;
- Memory.select(mybytearray);
- trace('Test: draw a '+width+'x'+height+' image '+iterations+' times');
- var start = getTime();
- var i:Int = 0;
- while(i <iterations) {
- var a = 0;
- while(a < testsize) {
- Memory.setI32(a,Memory.getI32(a));
- a+=4;
- }
- ++i;
- }
- trace('write32: ' + (getTime()-start) + 'ms');
- var start = getTime();
- var i:Int = 0;
- while(i <iterations) {
- var a = 0;
- while(a < testsize) {
- Memory.setDouble(a,Memory.getDouble(a));
- a+=8;
- }
- ++i;
- }
- trace('write64: ' + (getTime()-start) + 'ms');
- var start = getTime();
- var i:Int = 0;
- while(i <iterations) {
- var a = 0;
- while(a < testsize) {
- mybytearray.position = a;
- mybytearray.writeBytes(mybytearray,a,width*4);
- a+=width*4;
- }
- ++i;
- }
- trace('writeLine: ' + (getTime()-start) + 'ms');
- }
- static inline public function getTime():Int {
- return Std.int(haxe.Timer.stamp()*1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement