ts = timestamp()
mem = heapfree
out_a=#()
n=1000000
for i = 1 to 1000000 do out_a[i]=i
for i = 1 to 1000000 do
(
index=random 1 1000000
tmp=out_a[index]
out_a[index] =out_a[i]
out_a[i]=tmp
)
Time: 3369, Memory: 2024L
edit: copy/pasted wrong benchmark, above is correct
Interesting… when I run your code mem usage is still 56004288L for me
EDIT: What is even more interesting is that in 32-bit 3dsmax memory usage is 28010988L, half of 64-bit.
code above is altered, this is final:
ts = timestamp()
mem = heapfree
out_a = #()
for i = 1 to 1000000 do out_a[i]=i
for i = 1 to 1000000 do
(
index = random 1 1000000
tmp = out_a[index]
out_a[index] = out_a[i]
out_a[i] = tmp
)
format "Time: %, Memory: %
" (timestamp()-ts) (mem-heapfree)
edit: ran it a few times, it keeps giving me readings like these:
Time: 3392, Memory: 2184L
check if your heapsize is below 50-60mb. If it is, maxscript will GC when it runs out of memory midway through the loop, and give a wrong readout on mem usage.
mmm… back to the drawing board
heapsize+=100000000
176629628L
heapfree
100948432L
46154924
100947904L
#()
1000000
OK
OK
Time: 2697, Memory: 56004048L
OK
it’s a right place for encrypted file.
rename the attachment to mse and run…
ts = timestamp()
mem = heapfree
randomIndexes 1000000
format "Time: %, Memory: %
" (timestamp()-ts) (mem-heapfree)
-- Time: 896, Memory: 56056376L
i promise to open the code a little later
but the WINNER IS… LO! much more elegant solution than mine.
whats wrong with the random function?
edit:
so it’s necessary that there are no duplicate numbers in the resulting array?
(
start = timeStamp()
mem = heapfree
result=for i=1 to 1000000 collect
(
random 1 1e10
)
local end = timeStamp()
format "processing: % seconds heap: %
" ((end - start) / 1000.0) (heapfree-mem)
print result[2]
)
processing: 0.715 seconds heap: 1176L