[Closed] Bsearch to replace finditem with huge array?
here is a fast reference, I use stringstream to build a 500000 elements string , with 100000 matched , less than 3000ms , I insert 100 other strings , less than 400ms , test on max 2021
(
aa=#(
@"C:\Users\Administrator\Personal",
@"C:\Users\Administrator\Personal\3ds Max 2020",
@"C:\Users\Administrator\Personal\3ds Max 2021",
@"C:\Users\Administrator\Personal\3dsMax",
@"C:\Users\Administrator\Personal\Apowersoft",
@"C:\Users\Administrator\Personal\Apowersoft",
@"C:\Users\Administrator\Personal\Autodesk Application Manager",
@"C:\Users\Administrator\Personal\WeChat Files",
@"C:\Users\Administrator\Personal\WeChat Files\test.max",
@"C:\Users\Administrator\Personal\Windows Live"
)
global cc=""
for j = 1 to 10 do cc+=substituteString aa[j] "\\" "/"+","
fn test5d =
(
local ss = stringstream"",fmt ="%"
for i = 1 to 1000 do format fmt cc to:ss -- for 500000 elements , set i = 1 to 50000 , if use old version max , may very slow
ss as string
)
st = timestamp()
global bb = test5d()
format "Build Time: %ms\n" (timestamp()-st)
aa
)
(
st = timestamp()
findstrings=@"C:\Users\Administrator\Personal\WeChat Files"
ss=dotNetObject "System.Text.RegularExpressions.Regex" "" (dotnetclass "System.Text.RegularExpressions.RegexOptions").IgnoreCase
dd=ss.Split bb (substituteString findstrings "\\" "/")
sel=#() -- if just need the count , no need below , the time will hundreds ms with 500000 elements , the count is dd.count - 1
ss1 = stringstream""
for i = 2 to dd.count do format (findstrings + (substituteString (substring dd[i] 1 (ss.Match dd[i] ",").Index) "/" "\\") + ",") to:ss1
sel=ss.split ss1 ","
deleteitem sel sel.count
format "Search Time: %ms\n" (timestamp()-st)
sel.count
)
Where do you get that big array of filepaths from?
Maybe you could just use .net .GetFiles with a mask instead? or mxs built-in getFiles <wild_card_filename_string>
Thanks for the code,I tried on old version,3ds max 2013,
500000 elements string:
Build Time: 121261ms
Search Time: 11569ms
I will try all code in this post,thanks for all
I use a .dll file read all files and folders of a driver such as D:,then I want to count some directories or files which I need,all directories or files stored in a big array,that’s why I need a fastest way to do this job.
In order to use bsearch() you first need to sort the array, and that will be a killer, moreover if you use qsort().
I don’t think this is a good case for using bsearch().
This takes just 188ms for 500K items in an unsorted array, which in my opinion is pretty fast.
(
fn FindStringInArray arr str =
(
str += "*"
count=0
for i in arr where matchpattern i pattern:str do count+=1
return count
)
)
What is your performance goal?
this is exactly what I showed above … I don’t see performance issues either
OK,I did a test,it’s really fast,the matchpattern is the best solution,thank you all again.