Skip to main content
gamedev.net
🔒 Locked

speed prob

Started by kayX 3 replies 750+ views
Original Post
kayX
kayX
i run loop test on vb6 vb.net c# and vc7 the code is like this for(x=0; x<10000; x++) { for(y=0; y<1000l y++) { for(z=0; z<3; z++) { num[x*y+z] = 1; } } } and the vb equivelant code. but c# and c++ seems to be slower by 100+ how come?
Agony
Agony
I'm not an expert on benchmarking, but I do know that it is very difficult to create fair benchmarks, especially across various languages; it takes a lot of experience to do it well. There could be all sorts of reasons why your code is turning out as it does. Is your C code compiled in debug or release mode? What optimizations might the C compiler do, or the .NET runtime? It might be able to tell that those loops are completely useless, if that data isn't actually used for something, and thus it wisely skips them entirely.

Try increasing or decreasing the numbers by a noticeable amount. If the VB code's speed doesn't seem affected, it very well may be just skipping the loops completely. But if the speed scales appropriately, then it must be something else. You could always try looking at the disassembly of the C++ code, or the byte code for the C#/VB.NET code, and see how they differ. Something's definitely up, 'cause you're right, 100 times slower for C++/C# doesn't sound correct. What I would expect would be almost identical speeds for a simple loop structure like that.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
Sr_Guapo
Sr_Guapo
This is a shot in the dark, but maybe the languages handle nested loops differently. Try a similar test with only one loop:

for(int i=0; i < 10000; i++)    variable = 1;


You also have a small typo in the source you showed.

for(y=0; y<1000l y++)
should be:
for(y=0; y<1000; y++)

I assume you just did that in the post, since ?I doubt that would actually compile...


Make sure to check out all optimizations as well. Are you using the optimizing compiler for c++? Do you have it set for maximum speed? There are tons of little things you must make sure of when you run benchmarks.

Also, post the VB code just in case there is some discrepancy (like you forgot some zeros in the loop, so it was only 1/100 the length).
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
iMalc
iMalc
maybe you should post you vb equivalent code???
Kind of hard to do a comparison otherwise.

Are you really meaning to use upwards of 28Megabytes for this?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.