make some corrections for Bowen Http://www.cnblogs.com/heycup/archive/2011/01/24/1943012.html
Setvector in the original text SetPixels's test is problematic. He misled the Getvector getpixels some classmates, and did not know how much to read the blog's belief in it, but the last of the "hands are more meaningful" I very much agree.
I made a few changes to the code inside, removing all the extra performance costs.
1 varShape:shape =NewShape ();2Shape.graphics.beginFill (0xff0000);3Shape.graphics.drawRect (0, 0, 300, 300);4 Shape.graphics.endFill ();5 6 varBmd1:bitmapdata =NewBitmapData (2000, 2000);7 varBmd2:bitmapdata =NewBitmapData (300, 300);8 Bmd2.draw (shape);9 Ten varRect:rectangle =NewRectangle (10,10,80,80); One A vararr:vector.<uint> = Bmd2.getvector (NewRectangle (10, 20, 80, 80)); - varStart:int =Gettimer (); - for(varJ:int = 0; J < 9999; J + +) { the bmd1.setvector (rect, arr); - } -Trace"Setvector", Gettimer ()-start); - + varArr2:bytearray = Bmd2.getpixels (NewRectangle (10, 20, 80, 80)); -Start =Gettimer (); + for(j = 0; J < 9999; J + +) { Aarr2.position = 0; at bmd1.setpixels (rect, arr2); - } -Trace"SetPixels", Gettimer ()-start); - - varPoint:point =NewPoint (10, 10); -Start =Gettimer (); in for(j = 0; J < 9999; J + +) { - bmd1.copypixels (BMD2, rect, point); to } +Trace"CopyPixels", Gettimer ()-start); - the varMatrix:matrix =NewMatrix (0.8,0,0,0.8); *Start =Gettimer (); $ for(j = 0; J < 9999; J + +) {Panax NotoginsengBmd1.draw (Bmd2,matrix,NULL,NULL, rect); - } theTrace"Draw", Gettimer ()-start);
The test results are as follows
This is the effect of the release version because it is using Flash CS.
Conclusion Copypixels>setvector>draw>setpixels Although the results are consistent with the original text but the performance differences are not as exaggerated as in the original
I tried to add the number of loops to 99999.
Can see Setvector draw setPixels Three methods The gap is not really big
About Flash pixel Operation Setpixels,setvector,copypixels,draw Performance comparison