int[] | List<int> | Collection<int> | |
---|---|---|---|
for | 0,105 | 0,16 | 0,297 |
foreach | 0,172 | 0,34 | 0,551 |
IEnumerator | 11,562 | 0,883 | 0,937 |
Linq | 0,707 | 0,902 | 1,219 |
Int[] | List<Int> | Collection<Int> | |
---|---|---|---|
for | 0,238 | 0,297 | 0,395 |
foreach | 0,23 | 0,402 | 0,785 |
IEnumerator | 2,734 | 0,86 | 0,875 |
Linq | 0,75 | 1,258 | 1,543 |
avoid IEnumerator at all IEnumerator gave the unexpected result; it will be the bad idea to use it in a performance critical code and to use it all in comparison with another simpler syntaxes.
Collection or its descendants are not intended to improve performance I knew that before the test and here I’ve asserted it. Better to use it on upper abstraction level to bind interfaces and not in local or class scopes at all.
foreach slowed down performance myth is busted I supposed that foreach with its type casting at every turn will slow down performance. However it’s not. Moreover if iEnd index local variable is not used and at every turn array.Length or list.Count dereference occurs, for cycle results will be worse than the posted here. So in most real cases I can’t mark out for or foreach cycle. They both are good.
array[] is a little bit faster than List<>
Linq - I expected better results However I can’t give the conclusion about Linq here. Additional research is required.
No comments:
Post a Comment