[Gambas-user] About variable name and speed cycle time...

Gianluigi gradobag at gradobag.it
Fri Oct 20 14:58:38 CEST 2023


Il 20/10/23 12:09, Fabien Bodard ha scritto:
>
>
> Le ven. 20 oct. 2023 à 11:38, Fabien TONIUTTI 
> <fabien.toniutti at free.fr> a écrit :
>
>     Hi every one
>
>     Could you explain me one simple thing :
>
>     if i use interger variable like this :
>
>     Private myvariableforchristmas As Integer
>
>     or variable like this :
>
>     Private m As Integer
>
>
>     Do you think it will have influence on speed of my program?
>
>     thanks for your answer.
>
>
> ... no :-).
>
> Because internally the variable names does not matter.
>
>
>     ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
>
>
> -- 
> Fabien Bodard
>
> ----[http://gambaswiki.org/wiki/doc/netiquette  ]----

Hi,

You can verify this yourself with an empirical code like this:

[code]

Private $aVariables As New String[]

Public Sub Main()

   Print myShortVar()
   Print myShortVar()
   Print myShortVar()
   Print myLongVar()
   Print myLongVar()
   Print myLongVar()

End

Private Sub myShortVar() As String

   Dim StartTime, DiffTime As Float
   Dim s As String = "test"

   StartTime = Timer
   For i As Integer = 0 To 1000000
     $aVariables.Push(s)
   Next
   DiffTime = Timer - StartTime
   Return Str(DiffTime * 1000) & " from short var in msec"

End

Private Sub myLongVar() As String

   Dim StartTime, DiffTime As Float
   Dim sVeryLongMyVariable As String = "test"

   StartTime = Timer
   For i As Integer = 0 To 1000000
     $aVariables.Push(sVeryLongMyVariable)
   Next
   DiffTime = Timer - StartTime
   Return Str(DiffTime * 1000) & " from long var in msec"

End
[code]

Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231020/94dda051/attachment.htm>


More information about the User mailing list