Are Sub's more performant than Function's?

  • Thread starter Thread starter Phil Jones
  • Start date Start date
P

Phil Jones

I usually like to write Function's rather than Sub's that return a Bool
indicating whether the procudure was successfull (in some contextual way).

I usually do this as a matter of course, whether I immedately need that flag
or not (just so that the design is laid down well in the first instance in
case I need to use it later - which often enough I do).

What I was wondering is whether there's any perforance hit (slight as it may
be) that a Function returning a value incurs over a Sub.

I ask because I remember some talk within performance circles about if a
Function doesn't explicitly return a value it's a little bit slower - that
leads me to ask whether a Function is just inherently slower in the first
place.

Thanks oh wise VB gurus...:-)
===
Phil : NZ, Aotearoa
 
Phil Jones said:
What I was wondering is whether there's any perforance hit (slight as it may
be) that a Function returning a value incurs over a Sub.

You get nothing for free. If code has to be included to handle any returned
value, then there is more code to execute, which amounts to a 'slight' increase
processing time. As usual, if you only call the routine occasionally, miniscule
performance hits are not a problem, but if your calling on them from some long
running loop, the delay can add up to be significant. You must decide what
is appropreate for your current circumstances....

LFS
 
Phil,

In my opinion one of the last things to botter about.

When you want really time conusuming parts, look how much times you paint
something on your screen.

One pixel moving by the user from the form cost more time than you can win
in a century normally with what you are talking about now.

Assuming it is not for a PDA.

Just my thought,

Cor
 
Phil Jones said:
I usually like to write Function's rather than Sub's that return a Bool
indicating whether the procudure was successfull (in some contextual way).

I usually do this as a matter of course, whether I immedately need that
flag or not (just so that the design is laid down well in the first
instance in case I need to use it later - which often enough I do).

What I was wondering is whether there's any perforance hit (slight as it
may be) that a Function returning a value incurs over a Sub.

You may want to take a look at the IL produced by the compiler using the
"ILDASM.EXE" tool.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top