Notifications
Clear all
[Closed] makeUniqueArray with integers trick
Mar 30, 2016 8:00 pm
It’s not fantastic but perhaps it’s useful for someone…
‘makeUniqueArray’ for an array of integers is slower than converting the array to bitArray and then convert it back to Array.
Moreover, for the same price, you get your array sorted.
(
fn setRandomArray =
(
theArray = #()
for i = 1 to 500000 do
(
append theArray (random 10000 10020)
)
return theArray
)
t = timestamp()
theArray = makeUniqueArray (setRandomArray())
t1 = timestamp()
format "MXS1 took %s
" ((t1 - t)*.001)
format "theArray= %
" theArray
t2 = timestamp()
theArray = ((setRandomArray()) as BitArray) as Array
t3 = timestamp()
format "MXS2 took %s
" ((t3 - t2)*.001)
format "theArray= %
" theArray
OK
)
4 Replies
2 Replies
Mar 30, 2016 8:00 pm
all depends on size of original array and values in it.
(
t = timestamp()
m = heapfree
arr = (#(1, 999999999) as bitarray) as array
format "% => time:% memory:%
" arr (timestamp() - t) (m - heapfree)
)
(
t = timestamp()
m = heapfree
arr = makeuniquearray #(1, 999999999)
format "% => time:% memory:%
" arr (timestamp() - t) (m - heapfree)
)