Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Question de performance

3 réponses
Avatar
Jean Saint Jalmes
Bonjour,

Lorsqu'une routine d'extraction de chaine (String) est=20
appel=E9e de tr=E8s nombreuses fois dans une application,=20
quelle est la solution la plus performante entre l'appel=20
d'une fonction qui retoune un String comme ci-dessous :

'---------------------------------------------------------
Private sub Form_Load()
Dim Text1 as string
...
Text1 =3D Get_String
...
End Sub

Private function Get_String() as String
....
Get_String =3D .....
End function

'---------------------------------------------------------
Et l'appel d'une proc=E9dure avec passage du String en=20
param=E8tre :=20

Private Text1 as String ' Variable globale
=20
Private sub Form_Load()
Get_String Text1
End Sub
=20
Private Sub Get_String(Dest as String)
...
Text1 =3D ......
End Sub

'--------------------------------------------------------

Merci d'avance.

Jean

3 réponses

Avatar
François Picalausa
Hello!

Je te conseille un petit tour ici:
http://www.mvps.org/vb/tips/benchmarks.htm

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Jean Saint Jalmes" a écrit dans
le message de news:21ec01c427a2$24fdbb10$
Bonjour,

Lorsqu'une routine d'extraction de chaine (String) est
appelée de très nombreuses fois dans une application,
quelle est la solution la plus performante entre l'appel
d'une fonction qui retoune un String comme ci-dessous :

'---------------------------------------------------------
Private sub Form_Load()
Dim Text1 as string
...
Text1 = Get_String
...
End Sub

Private function Get_String() as String
....
Get_String = .....
End function

'---------------------------------------------------------
Et l'appel d'une procédure avec passage du String en
paramètre :

Private Text1 as String ' Variable globale

Private sub Form_Load()
Get_String Text1
End Sub

Private Sub Get_String(Dest as String)
...
Text1 = ......
End Sub

'--------------------------------------------------------

Merci d'avance.

Jean


Avatar
Ludovic SOEUR
Merci beaucoup François pour ce moyen de benchmarks. Ca va beaucoup me
servir !

"François Picalausa" a écrit dans le message de news:
On$
Hello!

Je te conseille un petit tour ici:
http://www.mvps.org/vb/tips/benchmarks.htm

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Jean Saint Jalmes" a écrit dans
le message de news:21ec01c427a2$24fdbb10$
> Bonjour,
>
> Lorsqu'une routine d'extraction de chaine (String) est
> appelée de très nombreuses fois dans une application,
> quelle est la solution la plus performante entre l'appel
> d'une fonction qui retoune un String comme ci-dessous :
>
> '---------------------------------------------------------
> Private sub Form_Load()
> Dim Text1 as string
> ...
> Text1 = Get_String
> ...
> End Sub
>
> Private function Get_String() as String
> ....
> Get_String = .....
> End function
>
> '---------------------------------------------------------
> Et l'appel d'une procédure avec passage du String en
> paramètre :
>
> Private Text1 as String ' Variable globale
>
> Private sub Form_Load()
> Get_String Text1
> End Sub
>
> Private Sub Get_String(Dest as String)
> ...
> Text1 = ......
> End Sub
>
> '--------------------------------------------------------
>
> Merci d'avance.
>
> Jean




Avatar
jmn
Ci après le code assembleur pour

function Function1$(byval a$)
function1= a & a
end function

et

sub Function2(byref a$)
a=a & a
end sub

Il est clair que la seconde version est nettement plus court, et donc plus
rapide, étant donné que VB n'a pas à gérer
l'éventuelle utilisation dans une expression (ce qui est une caractéristique
de base des fonctions).
CQFD.



************************************ Exemple 1 **************************
11: Function function1$(ByVal a$)
00401690 55 push ebp
00401691 8B EC mov ebp,esp
00401693 83 EC 08 sub esp,8
00401696 68 C6 10 40 00 push offset ___vbaExceptHandler
(004010c6)
0040169B 64 A1 00 00 00 00 mov eax,fs:[00000000]
004016A1 50 push eax
004016A2 64 89 25 00 00 00 00 mov dword ptr fs:[0],esp
004016A9 83 EC 0C sub esp,0Ch
004016AC 53 push ebx
004016AD 56 push esi
004016AE 57 push edi
004016AF 89 65 F8 mov dword ptr [ebp-8],esp
004016B2 C7 45 FC B0 10 40 00 mov dword ptr [ebp-4],offset
__imp____vbaFreeStr+40h (004010b0)
004016B9 8B 55 08 mov edx,dword ptr [a]
004016BC 33 C0 xor eax,eax
004016BE 8D 4D EC lea ecx,[a]
004016C1 89 45 EC mov dword ptr [a],eax
004016C4 89 45 E8 mov dword ptr [function1],eax
004016C7 FF 15 4C 10 40 00 call dword ptr [__imp____vbaStrCopy
(0040104c)]
12: function1 = a & a
004016CD 8B 45 EC mov eax,dword ptr [a]
004016D0 50 push eax
004016D1 50 push eax
004016D2 FF 15 10 10 40 00 call dword ptr [__imp____vbaStrCat
(00401010)]
004016D8 8B D0 mov edx,eax
004016DA 8D 4D E8 lea ecx,[function1]
004016DD FF 15 60 10 40 00 call dword ptr [__imp____vbaStrMove
(00401060)]
004016E3 68 FE 16 40 00 push offset $L70 (004016fe)
004016E8 EB 0A jmp $L36 (004016f4)
13: End Function
004016EA 8D 4D E8 lea ecx,[function1]
004016ED FF 15 70 10 40 00 call dword ptr [
(00401070)]
004016F3 C3 ret
$L36:
004016F4 8D 4D EC lea ecx,[a]
004016F7 FF 15 70 10 40 00 call dword ptr [
(00401070)]
$L68:
004016FD C3 ret
$L70:
004016FE 8B 4D F0 mov ecx,dword ptr [ebp-10h]
00401701 8B 45 E8 mov eax,dword ptr [ebp-18h]
00401704 5F pop edi
00401705 5E pop esi
00401706 64 89 0D 00 00 00 00 mov dword ptr fs:[0],ecx
0040170D 5B pop ebx
0040170E 8B E5 mov esp,ebp
00401710 5D pop ebp
00401711 C2 04 00 ret 4


************************************ Exemple 2 **************************
14:
15: Sub Function2(ByRef a$)
00401720 56 push esi
00401721 8B 74 24 08 mov esi,dword ptr [esp+8]
00401725 8B 06 mov eax,dword ptr [esi]
00401727 50 push eax
00401728 50 push eax
00401729 FF 15 10 10 40 00 call dword ptr [__imp____vbaStrCat
(00401010)]
0040172F 8B D0 mov edx,eax
00401731 8B CE mov ecx,esi
00401733 FF 15 60 10 40 00 call dword ptr [__imp____vbaStrMove
(00401060)]
00401739 5E pop esi
16: a = a & a
17: End Sub
0040173A C2 04 00 ret 4