Archived

This topic is now archived and is closed to further replies.

Functions: Performance-Killers?

This topic is 5005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I noticed that in VB .NET, calling a function needs much time, too much for some real-time algorithms... However, as I can''t implement all the code directly, I need something like the "inline" parameter in C, which speeds up the function-call... Does anybody know a solution? Thanks and greetings

Share this post


Link to post
Share on other sites
quote:
Original post by Nik02
VB is a bad choice if you are so concerned about performance.
Note that I''m not trying to start a flamewar here
Why don''t you use c++ for your application?



He said VB.NET, not VB6. Both C# and VB.NET compile to the same intermediate code, so they are just languages with a different syntax but the same results.
And I think the JIT compiler will inline functions whenever appropriate. Even if it doesn''t, calling a function isn''t that expensive, not even in .NET.

Share this post


Link to post
Share on other sites
Because
1. VB is not too bad in the .net version - of course C++ is better
2. I''m not that good at C++
3. I''m currently working at a school work that is to be presented in october in front of a bunch of conservative anti-gamers (teachers ;-), therefore the code has to be clear and easy to understand...

Share this post


Link to post
Share on other sites
A less radical solution might be to run the vb code through some kind of preprocessor (c''s, m4, etc) and implement the functions as macros.
Or you could rewrite the time critical parts in c as a dll or com object.

Share this post


Link to post
Share on other sites
quote:
Original post by Christoph
Because
1. VB is not too bad in the .net version - of course C++ is better
2. I''m not that good at C++
3. I''m currently working at a school work that is to be presented in october in front of a bunch of conservative anti-gamers (teachers ;-), therefore the code has to be clear and easy to understand...


1. VB is limited on many aspects
2. You should be able to learn C++, it would be a valuable experience... Plus you will have to switch someday, as VB is going to disappear.
3. I consider C++ code to be much clearer and much easier to understand than VB.



Looking for a serious game project?
www.xgameproject.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you sure that it is the calling of the functions that is too slow?
It seems infinitely more likely that the problem is with your algorithm or implementation than the function call itself.

-Extrarius

Share this post


Link to post
Share on other sites
No, I''ve made time tests with simple math operations, its the call.
And I have already learned C++, but I''m not good enough to write a complex game... With my C, it''s just as with French - I can understand it, but being active... well ;-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Max_Payne
2. You should be able to learn C++, it would be a valuable experience... Plus you will have to switch someday, as VB is going to disappear.
3. I consider C++ code to be much clearer and much easier to understand than VB.




2. I bet C++''s usage will drop much faster than VB''s. C++ is a static, complex, binding language that puts too much on the shoulders of the programmers. I foresee a future with languages like Python, Smalltalk or Lisp features.

3. That''s just you. I think Lisp''s syntax is the cleanest (and most beautiful) of any language.

Share this post


Link to post
Share on other sites
I just took the time elapsed during a great amount of calculations wich I execute in a loop; the results show that when I put a simple operation in a function the process is slowed down dramatically.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
how many times are you calling a function?

if you are doing:

for(int i = 0; i < INFINITY; i++)
{
call_a_function();
}

then you might think about doing this instead:

call_a_function(INFINITY);

and define

call_a_function(int num_times)
{
for(int i = 0; i < INFINITY; i++)
{
work;
}
}


that way you incur the function call overhead just once.

}

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
3. That''s just you. I think Lisp''s syntax is the cleanest (and most beautiful) of any language.


Him, and hundreds of thousands of others, you mean :-)

Anyway, for every Lisp lover there are 1000s of C++ lovers. The fact that C++ is loved by so many programmers out there means it''s not that horrible. As for your estimation about C++ dropping, well... I believe C++ will be just like Assembly. It will never fade out completely, and they will be used for anything serious.

The first lesson I''ve learned at college was that if your algorithm sucks, any tweak will be useless. On the same note, if your programming language sucks (by taking off the control from you) then no tweaks will help.

Share this post


Link to post
Share on other sites
quote:
Original post by DadleFish


The first lesson I''ve learned at college was that if your algorithm sucks, any tweak will be useless. On the same note, if your programming language sucks (by taking off the control from you) then no tweaks will help.




This is very enlightened view IMHO.

-Nik

Share this post


Link to post
Share on other sites
Cristoph: what exactly are you trying to do?

i only ask because "simple math operations" would generally be relatively fast, so a larger percentage of the time could be spend with function calls. if you write functions that actually do something complex, the function-call overhead percentage is reduced to a very small portion of the time spent overall.

Share this post


Link to post
Share on other sites
Of course it''s possible to construct a program where function call overhead makes up a lot of its time. But it shouldn''t occur under normal circumstances.

Are you
- Calling a lot of functions whose soul task is to call another function?
- Calling these inside tight loops
- Using recursion in a lot of cases where the called function simply returns without doing anything?

I don''t know the ins and outs of the vb.net compiler. But I imagine (possibly naively but I''m sure someone will correct me (they usually do (and often not terribly politely))) that if you don''t declare a function virtual, and call it inside the same assembly as you''re declaring it, it should be able to do inlining.

Even if it doesn''t do inlining at compiler time, the JIT might do it at load time.

Mark

Share this post


Link to post
Share on other sites
quote:
Original post by Nik02
VB is a bad choice if you are so concerned about performance.
Note that I''m not trying to start a flamewar here
Why don''t you use c++ for your application?

-Nik


Maybe not a flame war.... but this certainly has a little heat behind it

Share this post


Link to post
Share on other sites
OK Flame war started...

scripting languages replacing c++ for game development?? never! i can definatly see that trend happening in the busness sector, but not for real time games dude! the speed to ease of coding ratio comparing c++ to pything, is significantly larger than that of c++ to assembly. those ratios wont ever change regardless of cpu speed, sure phython interpretation speed will increase, but c++ execution speed wont degrease. and python is not that much easyer to use than c++ to ever warent the preformance drop one would encounter from using that language for games.

its just not practiacl to take a massive preformance hit, because you cant manage your own memory, put semi colons at the end of lines, or understand the concept of a pointer.

the preformance hit taken from going from assembly to c++ is ok because the speed to performance ratio between the 2 is small. but the ratio from python to c++ is a whole lot larger, and thus not worth the sacrafice for the small ease of use gained by that language.

LET THE BATTLE BEGIN

Share this post


Link to post
Share on other sites
quote:
Original post by DadleFish
The first lesson I''ve learned at college was that if your algorithm sucks, any tweak will be useless. On the same note, if your programming language sucks (by taking off the control from you) then no tweaks will help.


Taking control away is a bad thing? And no tweaks will help? I assume by that you''re advocating C++, which is ironic because it sounds like a mantra against C++ templates.

Share this post


Link to post
Share on other sites
quote:
Original post by Dobbs
Taking control away is a bad thing?


Depends on the context. I rather enjoy having a GC take care of memory off the heap for me, just leaving me to deal with references. Taking away control in this sense is fine. However, taking away control could also set the developer up for having to create more and more abstracted layers to deal with the limitations in the language, whereas a more powerful environment would require less work on their part.

quote:

And no tweaks will help?


Tweaks may or not help, depending on architecture. A graphics pipeline will be slowed down by its weakest link, tweaks and optimizations on anything else will not increase performance. A bubble sort would be different. You could rewrite the bubble sort in assembly language and hand tune every part that you could, but in the end you are dealing with O(N*N). Optimizing is most likely futile in the sense that you have a shitty algorithm to begin with.

quote:

I assume by that you''re advocating C++, which is ironic because it sounds like a mantra against C++ templates.

Huh?

Share this post


Link to post
Share on other sites
quote:
Original post by StentSoft
quote:
Original post by Nik02
VB is a bad choice if you are so concerned about performance.
Note that I''m not trying to start a flamewar here
Why don''t you use c++ for your application?

-Nik


Maybe not a flame war.... but this certainly has a little heat behind it


Please, people, there are more important thing to discuss
I tend to advice my peers, "choose the right tool for the right job" - worked for me so far.
I use c++, VB, c#, JS, php, IA 32 asm, PS/VS asm, HLSL and a few other languages professionally, almost all of which I use daily, and I''ve not found a single language which would outperform others in every possible situation.

-Nik

Share this post


Link to post
Share on other sites
quote:
Anyway, for every Lisp lover there are 1000s of C++ lovers. The fact that C++ is loved by so many programmers out there means it''s not that horrible.
Britney Spears was the top selling artist in 2002. I guess that makes her the best. She outsold Mozart and Bach combined!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
britney spears music is very good for what it is - "easy" pop music.

Share this post


Link to post
Share on other sites
quote:
Original post by Arild Fines
quote:
Original post by DadleFish
The fact that C++ is loved by so many programmers out there means it''s not that horrible.

Actually, it just means that people are stupid.


Okaaaay!?!?

So you say that most programmers on software houses and about 40-50% of the users of theese forums are stupid??

Get real!

And what gives you the right to declare people as stupid? Wonder who really qualifies to that title here.

Allmight

Share this post


Link to post
Share on other sites