Are contiguous C++ arrays really faster than Java/C# ArrayLists? -- StackOverflow

When you see anyone claim performance parity between <other language> and C++, one of the first things to look for is whether the C++ version of their test code is correctly using arrays and traversing them in order. If the test code is just doing equivalent pointer-chasing in both languages, the performance comparison is largely meaningless because the program is probably memory-bound and not properly written to use C++'s default container (vector).

Note: The question below has been modified since originally posted and now shows more reasonable numbers that demonstrate contiguous arrays are indeed faster. The comments are still enlightening to read, however.

Today on SO:

Unable to reproduce: C++ Vector performance advantages over C# List performance

At Microsoft's BUILD conference Herb Sutter explained that C++ has "Real Arrays" and C#/Java languages do not have the same or sort of.

I was sold on that. You can watch the full talk here

Here is a quick snapshot of the slide where he described this.

But I wanted to see how much difference will I make.

So I wrote very naive programs for testing, [...] Here are the results on my dell laptop with Core i7 processor:

count       C# (List<string>)   C# (ArrayList)     C++  
1000           24 ms              21 ms             7 ms      
10000         214 ms             213 ms            64 ms    
100000  2 sec 123 ms       2 sec 125 ms           678 ms

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.