473,770 Members | 5,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2234
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*******@disc ussions.microso ft.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 maintainablilit y 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*******@disc ussions.microso ft.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*********@ho tmail.com> wrote in message
news:xu******** ************@co mcast.com...

"code6" <an*******@disc ussions.microso ft.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(DllImpo rtAttribute()) 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*********@ho tmail.com> wrote in message
news:xu******** ************@co mcast.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
1521
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 trying hard to find out how to get it working with 'n' Characters, so you will be asked to enter a number at the beginning, asking you how many characters you want.
27
2394
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. It is available at: http://staff.washington.edu/sabbey/py_do Good background on thunks can be found in ref. . Simple Thunks
11
2713
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
4260
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 char* formatter, ...); Then, I want to call it as so:
16
8653
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
1781
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; namespace ConsoleProject1 { public class Base
5
1531
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
2088
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 teach myself this aspect of Python by working up a trial project, part of which calls for pulling in data from a serial data connection at regular intervals. It looked sensible to place all the comms procedures/functions in their own class and...
10
2136
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 System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http:// wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.