Notifications
Clear all

[Closed] Holdling keys and values inside struct

Now let’s try to add 5000 and find & collect 500.
I decided to not use mapPath struct this time

fullPaths = #() ; fileNames = #()
  randomVFGen &fullPaths &fileNames cnt:5000
  fewFiles = for i = 1 to 1000 collect fileNames[random 1 5000]

–>>> Result using .net Hashtable
–>>> Adding Method > time:0.182 memory:68416L
–>>> Finding Method > time:0.037 memory:170712L

–>>> Result using ListData struct
[color=Orange]–>>> Adding Method
> time:0.31 memory:324696L
–>>> Finding Method
> time:0.068 memory:[b]66320L

[/b][/color]BTW I tested this on laptop: ASUS i7 2630QM 2.0GH | 16GB DDR3 | win8.1×64 | max2014SP3 x64

What do you think Denis? After all you are right about .net Hashtable:thumbsup:

3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

the results were expected. strings, arrays,… the weak point in mxs. instead of adding python to max would be much better just re-write some things in mxs.

(@gazybara)
Joined: 11 months ago

Posts: 0

Yup. Your example shows everything. Pure mxs and still is a little differece in compare with .net Hashtable.
AD for sure need to read all your posts here and use it (all snippets) for software optimizations.
After that should give you an enormous amount of money or any subsequent version for free for a century

(@gazybara)
Joined: 11 months ago

Posts: 0

After all “mapPath” struct is not a perfect solution for this

the Hashtable is fast in real life. it’s slow just in max dotnet. with simple c# assembly you can make it works much faster.

you can find on this forum my c# solution for multidimensional arrays. something about 50 times difference with built-in. the dotnet in max is very unoptimized…

2 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

The only problem is : I not know c# programming. That’s why I avoid to use it in my scripts.

(@denist)
Joined: 11 months ago

Posts: 0

maxscript is fast… trust me

I tested now tree different .net collection types (Hashtable, StringDictionary, HybridDictionary)
Results are very similar. For test purpose I added 1million filename strings and search 100000.

fullPaths = #() ; fileNames = #()
randomVFGen &fullPaths &fileNames cnt:1000000
fewFiles = for i = 1 to 100000 collect fileNames[random 1 1000000]

Hashtable test

hsh = dotNetObject "System.Collections.Hashtable"
--ADD
gc() ; t1 = timestamp() ; m1 = heapfree
for i in 1 to fileNames.count where not (hsh.ContainsKey fileNames[i]) do hsh.Add fileNames[i] fullPaths[i]
format "Adding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
--FIND
gc() ; t1 = timestamp() ; m1 = heapfree
for p in fewFiles collect hsh.item[p]
format "Finding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

–>>> Result using .net Hashtable
–>>> Adding Method > time:34.824 memory:11903734L
–>>> Finding Method > time:1.232 memory:15836422L

[color=DeepSkyBlue]StringDictionary test
[/color]

(
sd = dotNetObject "System.Collections.Specialized.StringDictionary"
--ADD
gc() ; t1 = timestamp() ; m1 = heapfree
for i in 1 to fileNames.count where not (sd.ContainsKey fileNames[i]) do sd.Add fileNames[i] fullPaths[i]
format "Adding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
--FIND
gc() ; t1 = timestamp() ; m1 = heapfree
for p in fewFiles collect sd.item[p]
format "Finding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

–>>> Result using .net StringDictionary
–>>> Adding Method > time:36.824 memory:11904854L
–>>> Finding Method > time:1.576 memory:15836510L

HybridDictionary test

(
hd = dotNetObject "System.Collections.Specialized.HybridDictionary"
--ADD
gc() ; t1 = timestamp() ; m1 = heapfree
for i in 1 to fileNames.count where not (hd.Contains fileNames[i]) do hd.Add fileNames[i] fullPaths[i]
format "Adding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
--FIND
gc() ; t1 = timestamp() ; m1 = heapfree
for p in fewFiles collect hd.item[p]
format "Finding Method > time:% memory:%
" ((timestamp()- t1 as float)/1000) (m1-heapfree)
)

–>>> Result using .net [color=YellowGreen]HybridDictionary
–>>> Adding Method > time:35.36 memory:11904854L
–>>> Finding Method > time:1.232 memory:15836494L[/color]

Also I found another interesting type of collection (ConcurentDictionary) with more advanced methods but can not be used inside max . I really like the way for updating key values 🙁

I think that this can fix path string in many cases

fn correctPath str = 
(
	local rx = dotNetClass "System.Text.RegularExpressions.Regex"
	local rxo = (dotNetClass "System.Text.RegularExpressions.RegexOptions").IgnoreCase
	local m = #(datapair "
" "\
", datapair "	" "\	", datapair "\r" "\\r", datapair (@"^([\\.$]+)") "\\\\", datapair (@"^([ \ .$]+)") "\\")
	for i = 1 to m.count do (str = rx.Replace str m[i].v1 m[i].v2 rxo)
	pathConfig.convertPathToAbsolute str
)
 /*
 str1 = "c:\The Things\TORE HOUSE
MXS\realMax_2014_Webcast_final\recording	ext.txt"
 str2 ="\\\\\\	omeServer\\/\rooot/
est"
 correctPath str1
 correctPath str2
 */
Page 2 / 2