ByVal or Byref : performance question ? 
Author Message
 ByVal or Byref : performance question ?

What is the fastest way to pass a control reference to a method ?
ByVal or Byref.

Knowing the following informations from the book "{*filter*} Visual Basic"
from Microsoft Press :

Problem Native Code P-Code
Integer by value 0.0063 sec 0.2508 sec
Integer by reference 0.0069 sec 0.2518 sec
Long by value 0.0073 sec 0.2563 sec
Long by reference 0.0072 sec 0.2553 sec
Single by value 0.0072 sec 0.2521 sec
Single by reference 0.0073 sec 0.2585 sec
Double by value 0.0078 sec 0.2579 sec
Double by reference 0.0073 sec 0.2599 sec
Variant by value 0.1585 sec 0.5561 sec
Variant by reference 0.0602 sec 0.4222 sec
String by value 0.3388 sec 0.8279 sec
String by reference  0.1669 sec 0.5901 sec

Control by value ?
Control by reference ?
Object by value ?
Object by reference ?
...

Please, if you have any ideas complete !



Mon, 21 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?
Salut:

Even if you use ByVal when passing objects (which includes controls) to a
method, they are actually still passed ByRef.  If you tested speed, I would
thus guess that you would find no difference.

John.....

Quote:

> What is the fastest way to pass a control reference to a method ?
> ByVal or Byref.

> Knowing the following informations from the book "{*filter*} Visual Basic"
> from Microsoft Press :

> Problem Native Code P-Code
> Integer by value 0.0063 sec 0.2508 sec
> Integer by reference 0.0069 sec 0.2518 sec
> Long by value 0.0073 sec 0.2563 sec
> Long by reference 0.0072 sec 0.2553 sec
> Single by value 0.0072 sec 0.2521 sec
> Single by reference 0.0073 sec 0.2585 sec
> Double by value 0.0078 sec 0.2579 sec
> Double by reference 0.0073 sec 0.2599 sec
> Variant by value 0.1585 sec 0.5561 sec
> Variant by reference 0.0602 sec 0.4222 sec
> String by value 0.3388 sec 0.8279 sec
> String by reference  0.1669 sec 0.5901 sec

> Control by value ?
> Control by reference ?
> Object by value ?
> Object by reference ?
> ...

> Please, if you have any ideas complete !



Mon, 21 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?

Quote:

>Salut:

>Even if you use ByVal when passing objects (which includes controls) to a
>method, they are actually still passed ByRef.  If you tested speed, I would
>thus guess that you would find no difference.

ByVal must be a little slower, because VB increments the reference count
when objects are passed ByVal (prevents the destination routine from
terminating the object).

Jim Deutch
MS Dev MVP



Mon, 21 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?
Rponse l'intuition qui vaut ce qu'elle vaut mais il me semble certain que
si le paramtre est un objet, VB dans sa cuisine interne doit ncessairement
passer un pointeur, ventuellement un pointeur sur un pointeur (l'objet lui
mme) si byref et un pointeur simple si byval. Je parierai mme que pour un
objet le passage effectif est le mme dans les deux cas. Donc je mets 10$
pour dire qu'il n'y a pas de diffrence...
J'espre t'avoir pas trop fait perdre ton temps :)


Mon, 21 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?
Jim:

Good point.  I did a quick test and found that on my Celeron 366 a loop of
500,000 took .5secs longer passing a collection object to a function with ByVal
rather than ByRef.  This is about about 1 microsecond per function call.
Normally this would not be significant enough to be the deciding factor in
choosing between ByVal and ByRef, but it is just as well to know about it.

John.......

Quote:


> >Salut:

> >Even if you use ByVal when passing objects (which includes controls) to a
> >method, they are actually still passed ByRef.  If you tested speed, I would
> >thus guess that you would find no difference.

> ByVal must be a little slower, because VB increments the reference count
> when objects are passed ByVal (prevents the destination routine from
> terminating the object).

> Jim Deutch
> MS Dev MVP



Tue, 22 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?

Quote:
> Jim:

> Good point.  I did a quick test and found that on my Celeron 366 a loop of
> 500,000 took .5secs longer passing a collection object to a function with
ByVal
> rather than ByRef.  This is about about 1 microsecond per function call.
> Normally this would not be significant enough to be the deciding factor in
> choosing between ByVal and ByRef, but it is just as well to know about it.

But it's also worth knowing that it would have been the other way round if
the function had been in an out-of-process component.  In that case ByVal
wins for passing objects because the marshalling overhead only happens
outbound.

Bertie



Tue, 22 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?

Here is the result of our reflexion :

http://www.experts-exchange.com/Computers/Programming/Windows/Visual_...
.10191014

Regards.

Jean-Philippe FORTI.



Fri, 25 Jan 2002 03:00:00 GMT  
 ByVal or Byref : performance question ?
Traditionally, people provide answers here, not pointers to
other services where they have placed the answer.

--
MichKa

-------------------------------------
don't send questions by e-mail unless
you're paying for it. (TANSTAAFL!) :-)

random junk of dubious value is at:
http://www.trigeminal.com


Quote:

> Here is the result of our reflexion :

http://www.experts-exchange.com/Computers/Programming/Window
s/Visual_Basic/Q
Quote:
> .10191014

> Regards.

> Jean-Philippe FORTI.



Fri, 25 Jan 2002 03:00:00 GMT  
 
 [ 23 post ]  Go to page: [1] [2]

 Relevant Pages 

1. ByVal or Byref : performance question ?

2. Questions regarding objects, assignments, byval, byref, etc...

3. Passing Parameters - A ByRef vs ByVal Question

4. Override ByRef with ByVal

5. ByVal / ByRef

6. byVal vs ByRef

7. Change Standard from ByVal to ByRef

8. Event Arguments : ByRef or ByVal (Which Best)?

9. Peformance in VB.NET - ByRef and ByVal

10. objects byval and byref

11. ByRef And ByVal for Object

12. byval / byref

 

 
Powered by phpBB® Forum Software