My flash benchmarks show array being quite slow in comparison to optimized linked lists - FastList and my implementation of singly and doubly linked list. But it's still a lot faster than List.
0.786 Haxe_List
0.434 ARRAY_MANUAL
0.357 Haxe_FastList_Manual
0.212 Dd_LinkedList
0.209 Dd_SinglyLinkedList
0.101 ARRAY
0.046 Dd_SinglyLinkedList_Manual
0.040 Dd_LinkedList_Reverse
0.035 Dd_LinkedList_Manual
0.031 Dd_SinglyLinkedList_Fast
0.017 Haxe_FastList
0.015 For
0.014 While
Scores postfixed with "Manual", "Fast" and "Reverse" used this form of iteration:
var iterator = structure.iterator();
while( iterator.hasNext() ) {
x += iterator.next();
}
This form of iteration benefits from inline iterator methods.
Dd_SinglyLinkedList_Fast iterator has some functionality stripped so it a bit faster.
Dd_LinkedList_Reverse iterator iterates from the end to the beginning.
Scores without postfix used this form of iteration:
for( i in structure ) {
x += i;
}
"While" stands for:
var i = 0;
while ( i < range )
{
x += i;
++i;
}
"For" stands for:
for ( i in 0...range )
{
x += i;
}
Let's check the results from fastest to slowest:
0.015 For
0.014 While
Very fast as expected.
0.017 Haxe_FastList
For iteration is very optimized on the compiler level so it ranked right behind for and while.
0.046 Dd_SinglyLinkedList_Manual
0.040 Dd_LinkedList_Reverse
0.035 Dd_LinkedList_Manual
0.031 Dd_SinglyLinkedList_Fast
My implementations using manual iteration follow. This shows the benefit of inlined iterator methods.
0.101 ARRAY
Array time is quite good. There are probably some compiler optimizations at work here.
0.212 Dd_LinkedList
0.209 Dd_SinglyLinkedList
My implementations using for iteration follow. The hit from calling iterator methods rather than inlining them is apparent.
0.357 Haxe_FastList_Manual
It seems manual iteration is missed by optimization of for iteration and ends up with a very bad time.
Array manual iteration follow. Probably same
0.786 Haxe_List
Epic fail :] Probably no inlining here. Also List uses arrays internally to store links. If it used class fields it would perform better on flash. I think manual iteration is quite the same, so it is omitted from benchmark.