[AccessD] Swap two elements in an array
Arthur Fuller
fuller.artful at gmail.com
Fri Aug 26 06:58:54 CDT 2022
Stuart,
Please explain why it's better to have separate functions for each data
type rather than using Variants. How much faster is it using separate
functions as opposed to a single function that works with variants? Is it
worth the trouble? From your own benchmarks, I don't see the advantage; if
performance were that critical, I'd guess that VBA is the wrong language in
the first place.
On Fri, Aug 26, 2022 at 1:17 AM Stuart McLachlan <stuart at lexacorp.com.pg>
wrote:
> It's really not worth the extra effort.
>
> The variant swap takes twice as long as the integer swap, but the
> difference is only about
> 0.156 seconds versus 0.0781 seconds per million iterations on my old
> laptop.
> That's 0.078 milliseconds faster per thousand calls to the function.
>
>
> On 26 Aug 2022 at 14:37, Stuart McLachlan wrote:
>
> > Oops! Too quick!
> > I messed those last two functions up badly :(
> >
> > Actually, the return value assignment is hardly necessary and you
> > could make the functions marginally faster again by not setting a
> > return value.
> >
> > Function iSwap(x As Long y As Long) As Boolean
> > 'swap integral variables
> > Dim t As Long
> > t = x
> > x = y
> > y = t
> > End Function
> > Function fSwap(x As Double, y As Double) As Boolean
> > 'Swap float variables
> > Dim t As Double
> > t = x
> > x = y
> > y = t
> > End Function
> > Function sSwap(x As String, y As String) As Boolean
> > 'swap string variables
> > Dim t As String
> > t = x
> > x = y
> > y = t
> > End Function
> >
> >
> >
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
--
Arthur
More information about the AccessD
mailing list