Posts tagged: benchmark

Fastest way to populate a complete Matrix3D (initialize a Vector)

I wanted to find out the fastest way to populate a complete Matrix3D this really comes down to the fastest way to initialize a Vector.

I made a quick bench mark the results where interesting to know:

test1: 2078ms
var m1:Vector.<Number> = Vector.<Number>([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);

test2: 869ms

var m2:Vector.<Number> = new Vector.<Number>();
m2.push(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

test3: 1586ms

var m3:Vector.<Number> = new Vector.<Number>();
m3[0]=1; m3[1]=0; m3[2]=0; m3[3]=0;
m3[4]=0; m3[5]=1; m3[6]=0; m3[7]=0;
m3[8]=0; m3[9]=0; m3[10]=1; m3[11]=0;
m3[12]=0; m3[13]=0; m3[14]=0; m3[15]=1;

I have seen plenty of code using test1 which you might think the correct method but flash is in fact creating a new array and a new vector then stepping through the slower array to populate the vector.

Test2&3 where quite interesting I would have said they would be about the same if anything test3 might have been faster.

Populating the Matrix, obvious really but had to check…

test4: 320ms
var mx1:Matrix3D = new Matrix3D(m4);

test5: 362ms

var mx2:Matrix3D = new Matrix3D();
mx2.rawData = m4;

Creating the class instance has the bigger overhead, so nout in it.

I then wondered if having a fixed vector size would be faster not much in but also worth noting.

test6: 995ms

var m5:Vector.<Number> = new Vector.<Number>(15);
m5.push(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

test7: 864ms

var m6:Vector.<Number> = new Vector.<Number>();
m6.push(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

Results based on 600000 operations each on a (IntelC2Quad2.4)

Mediastation Creative Solutions Ltd