Notifications
Clear all

[Closed] Maxscript challenge ideas

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

 lo1

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

-double post due to forum overload-

 lo1

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.

heapsize
76634260L

edit: using Max2012 64 bit

 lo1

but is ‘heapfree’ over 56mb?
try heapsize+=100000000 just in case

1 Reply
(@jonadb)
Joined: 11 months ago

Posts: 0

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.

 lo1

yet yours run twice as fast. Waiting to see the code…

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
Page 3 / 12