开发者

Rationale behind these performance numbers: Arrays vs Lists C#

Can anyone explain the reasons the numbers in this post are the way they are?

Performance of Arrays vs. Lists

I was curious why the iterator for list performs so poorly but开发者_开发问答 the for indexer was so close.


There's probably very little in the way of the List indexer and the array indexer so it makes sense that they're very close in timing (i.e., the list implementation chains to the array implementation with not much if anything in-between).

I'm guessing on the iterator, but the List implementation would need to check for error conditions such as concurrent modification and bounds violations. It's probably written with a yield as well. These would have a small impact, but we're talking micro-differences here.

To really answer this, you could step into the framework source via the source code reference server.


It isn't clear from your question which results you are referring to, but I'll assume it's Marc's analysis (the currently accepted answer). Looking at the comments in both his answer and some of the other answers, there seems to be some uncertainty about the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜