[Gambas-user] Speaking of optimizations
Charlie Ogier
charlie at cogier.com
Mon Mar 18 17:19:39 CET 2019
I can't see the point of using .Max when you have already fixed the
array size to 100. It's best used when you don't know how big the array
will be, for example: -
/Public Sub Form_Open()//
//Dim sList As String[] = Dir(User.Home)//
//
//For iFile As Integer = 0 To sList.Max//
// Print sList[iFile]//
//Next//
//
//Print//
//Print "Number of files = " & Str(sList.Max)//
//
//End//
/
Charlie
On 17/03/2019 18:01, Cedron Dawg wrote:
> I just found out about the .Max property of arrays, saving having to do a .Count - 1.
>
> I like it, but the name is a little confusing to me, I thought it would mean MaxValue, not MaxIndex. No I can't think of a better short word. "Top" is misleading, so is "Limit".
>
> My real question is a performance related one. Given:
>
> Dim a As New String[100]
> Dim i, m As Integer
> .
> .
> m = a.Max
> For i = 0 To m
> ...
> Next
> .
> .
> For i = 0 To a.Max
> ...
> Next
>
> Does the first loop give any performance advantage over the second one? Or does the compiler recognize that "a" won't change size in the loop and implement the first form under the covers?
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190318/da89b2b7/attachment.html>
More information about the User
mailing list