removed1's blog

By removed1, 14 years ago, translation, In English

Continuing this thread

http://codeforces.com/comments/264#comment-3078 (in Russian)

[disclaimer: these measurements are not accurate, they are like measuring RPM of engine during idle run, instead of time of racing car on track.., were not statistically tested, etc.]

I took maslowmw's code, changed size to 500, removed time printing (which doesn't make big difference) and tried it in Topcoder Practice Rooms. Indeed, 2d array in .NET version used at Topcoder, is slower than array-of-array (I think it should change in future, if not already: latest MS.NET version is 4.0). I got interested and tried several other variants. Here are the results, and make conclusions yourselves.

c#:
[i][j]: 1.328s
[i,j]: 1.516s
[i*size+j]: 0.875s

c++:
int [][]: 0.266s
int **: 0.791s
[i*size+j]: 0.286s % where size = const int
[i*size+j]: 0.695s % where size = input parameter
vector<vector<int>> : 0.478s % where size = const int
vector<vector<int>> : 0.608s % where size = input parameter

java:
[i][j]: 1.927s
[i*size+j]: 1.306s

P.S.? After I clicked 'Know English' link to translate my post into English, the website removed my original tags and replaced them with "c++", "c#", "best language". WHO WROTE THIS CODE, AND WHY? Puzzle.

  • Vote: I like it
  • 0
  • Vote: I do not like it