473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

quite simple question on calling functions

does calling a regular function cost any cpu time? In other words, is it
faster to write the code of two functions into main(), or is it the exact
same thing as calling two functions. I know its nitty gritty but its
necessary for my program.
thanks
dave
Nov 15 '05 #1
5 2200
if you are that worried about speed, i suggest you go
learn assembler and quit messing with a language that
runs thru the .net framework... aka compiled to IL before
being finally comiled to machine code as the app executes
thru the .net runtime.

yes there is over head in function calling, but for
christ sake what are you gaining other than a nasty
poorly designed app? if you you think it's slow because
you have two functions, you should seriously consider
rethinking what those functions are doing, and the types
of the parameters as well as how they are being passed.

passing large objects back and forth is going to eat ram
and run slower... that's pretty obvious.

can you provide a snippet of what you feel is causing the
slowdown? chances are that it's not just having two
functions, but more in their design.
-----Original Message-----
does calling a regular function cost any cpu time? In other words, is itfaster to write the code of two functions into main(), or is it the exactsame thing as calling two functions. I know its nitty gritty but itsnecessary for my program.
thanks
dave
.

Nov 15 '05 #2

"code6" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
if you are that worried about speed, i suggest you go
learn assembler and quit messing with a language that
runs thru the .net framework... aka compiled to IL before
being finally comiled to machine code as the app executes
thru the .net runtime.

yes there is over head in function calling, but for
christ sake what are you gaining other than a nasty
poorly designed app? if you you think it's slow because
you have two functions, you should seriously consider
rethinking what those functions are doing, and the types
of the parameters as well as how they are being passed.
Its a relevent question, no need to go nuts over it.

However, I advise you write for maintainablility and worry about performance
at that level AFTER the app works. Two methods, while there MAY be some
minor overhead is pretty irrelevent over all. Write your methods in logical
divisions of duty.

For small, non-virtual methods, the JIT is free to, and probably will,
inline the code, eliminating any overhead from the call. In larger methods,
the execution of the method body is the major factor, not the time to call
into that method body.
Calling virtual or interface methods may have additional performance issues.

You may want to take a look at your looping, that is more likely an issue
than method calls. Your code is likely making alot more method calls than
you realize.
passing large objects back and forth is going to eat ram
and run slower... that's pretty obvious.
Actually, large or small, objects are referenced, not passed around by value

string MyFunction()
{
string LargeString = //"few megs of text loaded from somewhere";
return LargeString;
}

string a,b,c;
a=LargeString();
b=LargeString();
c=LargeString();

takes up no significant extra memory. however, large structures can cause
you problems.
can you provide a snippet of what you feel is causing the
slowdown? chances are that it's not just having two
functions, but more in their design.
-----Original Message-----
does calling a regular function cost any cpu time? In

other words, is it
faster to write the code of two functions into main(),

or is it the exact
same thing as calling two functions. I know its nitty

gritty but its
necessary for my program.
thanks
dave
.

Nov 15 '05 #3

"code6" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
if you are that worried about speed, i suggest you go
learn assembler and quit messing with a language that
runs thru the .net framework... aka compiled to IL before
being finally comiled to machine code as the app executes
thru the .net runtime.

yes there is over head in function calling, but for
christ sake what are you gaining other than a nasty
poorly designed app? if you you think it's slow because
you have two functions, you should seriously consider
rethinking what those functions are doing, and the types
of the parameters as well as how they are being passed.

passing large objects back and forth is going to eat ram
and run slower... that's pretty obvious.

can you provide a snippet of what you feel is causing the
slowdown? chances are that it's not just having two
functions, but more in their design.
-----Original Message-----
does calling a regular function cost any cpu time? In

other words, is it
faster to write the code of two functions into main(),

or is it the exact
same thing as calling two functions. I know its nitty

gritty but its
necessary for my program.
thanks
dave
.

I'm just trying to figure out how to write the fastest program possible for
a research project which will include artifical intelligence and quantum
physics calculations. Its going to simulate chemical reactions on the
screen and in the mean time I plan to make it able to find easier ways to
calculate the same things because some of the calculations that it will do
will be redundant. that's what the artificial intelligence is for. but the
point is that the program will be hopelessly time consuming if it was fully
functional. In fact, it could take days if not longer to simulate something!
If you can suggest a good way to easily build a program that integrates
windows forms, directx graphics, and very fast code PLEASE PLEASE PLEASE
tell me. C# is just so easy to work with because it is visual but I also
know how to program in C and am only barely familiar with assembly.
thanks
dave
Nov 15 '05 #4

"Dave" <da*********@hotmail.com> wrote in message
news:xu********************@comcast.com...

"code6" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
if you are that worried about speed, i suggest you go
learn assembler and quit messing with a language that
runs thru the .net framework... aka compiled to IL before
being finally comiled to machine code as the app executes
thru the .net runtime.

yes there is over head in function calling, but for
christ sake what are you gaining other than a nasty
poorly designed app? if you you think it's slow because
you have two functions, you should seriously consider
rethinking what those functions are doing, and the types
of the parameters as well as how they are being passed.

passing large objects back and forth is going to eat ram
and run slower... that's pretty obvious.

can you provide a snippet of what you feel is causing the
slowdown? chances are that it's not just having two
functions, but more in their design.
-----Original Message-----
does calling a regular function cost any cpu time? In other words, is it
faster to write the code of two functions into main(),

or is it the exact
same thing as calling two functions. I know its nitty

gritty but its
necessary for my program.
thanks
dave
.

I'm just trying to figure out how to write the fastest program possible

for a research project which will include artifical intelligence and quantum
physics calculations. Its going to simulate chemical reactions on the
screen and in the mean time I plan to make it able to find easier ways to
calculate the same things because some of the calculations that it will do
will be redundant. that's what the artificial intelligence is for. but the point is that the program will be hopelessly time consuming if it was fully functional. In fact, it could take days if not longer to simulate something! If you can suggest a good way to easily build a program that integrates
windows forms, directx graphics, and very fast code PLEASE PLEASE PLEASE
tell me. C# is just so easy to work with because it is visual but I also
know how to program in C and am only barely familiar with assembly.
thanks
dave
If you need blazing code, I'd suggest building a C\C++ library that does it
and talks to the winforms host via a chunky call. Unfortunatly there are
some issues with managed code that may cause performance degredation in
situations like yours(I'm not saying the performance will be bad, just that
you can probably do better).

Without knowing the specifics of your app, I assume you perform calculations
over some particular set of data and that the simulation processing is the
major chunk of code, not the display or data loading. In that case, I'd
write, to whatever level you need in C in a way that performs as much work
per call as possible and then interface with that in C# to perform the UI
work.

Basically, look into PInvoke(DllImportAttribute()) and see if that will suit
your needs. If it will, import the function calls you need(I'd suggest as
few as possible), and run it on a seperate thread, stoping occasionally to
issue information to the UI and restart processing.

Also, you may want to look into intel's C++ compiler, I've used it a time or
two on CRC and MD5 hashing code and seen perceptible performance increases,
it may be of value...or it may not, I don't know.

Nov 15 '05 #5
See the link in the thread I started about performance comparison between
C#, C++, and java.

Only you know exactly what you mean by "very fast code". Does that mean
"fast enough" given a powerful enough box, or does that mean you'll be
graded on the performance relative to the other students?

"Dave" <da*********@hotmail.com> wrote in message
news:xu********************@comcast.com...
I'm just trying to figure out how to write the fastest program possible for a research project which will include artifical intelligence and quantum
physics calculations. Its going to simulate chemical reactions on the
screen and in the mean time I plan to make it able to find easier ways to
calculate the same things because some of the calculations that it will do
will be redundant. that's what the artificial intelligence is for. but the point is that the program will be hopelessly time consuming if it was fully functional. In fact, it could take days if not longer to simulate something! If you can suggest a good way to easily build a program that integrates
windows forms, directx graphics, and very fast code PLEASE PLEASE PLEASE
tell me. C# is just so easy to work with because it is visual but I also
know how to program in C and am only barely familiar with assembly.
thanks
dave

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mx2k | last post by:
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
16
by: News VS.NET \( MS ILM \) | last post by:
Hello VC, Given a non-DotNET dll from some unknown place How do I know the classes in it, or how do I view the classes, methods, properties etc.. Thank you
1
by: relient | last post by:
Hi, I just started the chapter on "Inheritance" and I'm a bit confused so I have three questions: first, here's the code: using System; using System.Collections.Generic; using System.Text; ...
5
by: Koliber (js) | last post by:
does anybody could tell me how can i do a 'simple c++ dll I compiled' - calling from my c# code (when I try adding this dll to references' it ays that it should be com) ? T I A jS
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.