[AccessD] Swap two elements in an array

Stuart McLachlan stuart at lexacorp.com.pg
Fri Aug 26 00:16:56 CDT 2022


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
> 




More information about the AccessD mailing list