mIRC Home    About    Download    Register    News    Help

Print Thread
Can this be done faster? #132231
08/10/05 06:20 AM
08/10/05 06:20 AM
Joined: Dec 2002
Posts: 1,527
state of confusion
L
landonsandor Offline OP
Hoopy frood
landonsandor  Offline OP
Hoopy frood
L

Joined: Dec 2002
Posts: 1,527
state of confusion
/f4 {
dialog -m mp3player mp3player | var %dialog.mp3s $findfile($sound(mp3),*.mp3,0)
while (%dialog.mp3s > 0) { did -a mp3player 20 $nopath($findfile($sound(mp3),*.mp3,%dialog.mp3s)) | dec %dialog.mp3s 1 }
}

When I use that, it takes about 2 minutes (locks mirc) to list all my mp3s in the listbox. If I use the following:

/mp32 {
if ($window(@MP3)) { clear -@ @MP3 }
if (!$window(@MP3)) { window -Ensk0 @MP3 Times New Roman,11 | font @MP3 11 Times New Roman }
!.echo -q $findfile(c:\multimedia files\,*.mp3,0,aline -l 9 @MP3 $nopath($longfn($1-))).shortfn
}


it takes about 9 seconds to list them all (granted it's in a custom window and not a dialog). Is there ANY way I can speed up the listing?? When using !.echo -q $findfile(c:\multimedia files\,*.mp3,0,aline -l 9 @MP3 $nopath($longfn($1-))).shortfn tweaked slightly, it took even longer than the method above.


Those who fail history are doomed to repeat it
Re: Can this be done faster? #132232
08/10/05 09:04 AM
08/10/05 09:04 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
hixxy  Offline
Hoopy frood
H

Joined: Sep 2005
Posts: 2,876
You should never loop with $findfile(,,N). Here's why:

$findfile(c:\,*,0) - loops through every file in the directory increasing a variable each time and then returns it.
$findfile(c:\,*,1) - loops through files until it finds the 1st matching file.
$findfile(c:\,*,100) - loops through files until it finds the 100th matching file.

So, if you have 10 files in a directory looping with $findfile(,,N) will have to go through 55 (10+9+8+7+6+5+4+3+2+1) files, not 10. As you can imagine this number will increase greatly when you have 100s of files.

When you use $findfile(,,0,command) it will only loop through the files in the directory once. This greatly speeds up any listing process.

As for your actual question: no, there's not a faster way to list files. $findfile uses the fastest method of listing files available on windows. If it's the locking up you're bothered about more than the speed you could use WhileFix.dll (available in mircscripts.org's dll section) to stop the freezing, but the files will take even longer to list then.

I'd imagine the speed would increase slightly if you didn't use the $longfn() identifier with the .shortfn property though ($findfile passes long filenames by default, so it makes no sense to do that).

Re: Can this be done faster? #132233
08/10/05 11:01 AM
08/10/05 11:01 AM
Joined: Apr 2003
Posts: 701
Leuven, Belgium
K
Kelder Offline
Hoopy frood
Kelder  Offline
Hoopy frood
K

Joined: Apr 2003
Posts: 701
Leuven, Belgium
Maybe hide the window before doing the $findfile so that the /aline doesn't trigger a screen refresh. Using /fwrite to a temp file and then /loadbuf into the window might help too, not sure about it though...

Re: Can this be done faster? #132234
08/10/05 01:47 PM
08/10/05 01:47 PM
Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
M
Mpdreamz Offline
Hoopy frood
Mpdreamz  Offline
Hoopy frood
M

Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
using var to trigger the $findfile will speed up slightly around a 100ms or so. That combined with the unnecessary identifiers as mentioned by hixxy will save you around a 1000ms! there was no need for the font command so i removed it.

Code:
alias mp32 {
  var %t = $ticks
  if ($window(@MP3)) { clear -@ @MP3 }
  if (!$window(@MP3)) { window -hEnsk0 @MP3 Times New Roman 11 }
  var %x = $findfile(D:\Mp3\,*.mp3,0,aline @MP3 $nopath($1-))
  echo -a this took $calc($ticks - %t) miliseconds for %x files
  window -r @mp3
}


this took 40 ms on 112 files

Kelder i dont know i go about this correctly but using fopen was actually slower as the original code smirk
Code:
alias mp32 {
  fopen -o list list.txt
  var %t = $ticks
  if ($window(@MP3)) { clear -@ @MP3 }
  if (!$window(@MP3)) { window -Ensk0 @MP3 Times New Roman 11 }
  var %x = $findfile(D:\Mp3\,*.mp3,0,.fwrite -n list $nopath($1-))
  fclose list | loadbuf @mp3 list.txt
  echo -a this took $calc($ticks - %t) miliseconds for %x files
}

that took 1823 ms on 112 files

Last edited by Mpdreamz; 08/10/05 01:52 PM.

$maybe
Re: Can this be done faster? #132235
08/10/05 04:54 PM
08/10/05 04:54 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
hixxy  Offline
Hoopy frood
H

Joined: Sep 2005
Posts: 2,876
Yes. I think he's talking about using playlists rather than just loading a directory every time. So you write all of the files in a directory to the file once, then each time you want to load the playlist you use /loadbuf.

Re: Can this be done faster? #132236
08/10/05 05:39 PM
08/10/05 05:39 PM
Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
M
Mpdreamz Offline
Hoopy frood
Mpdreamz  Offline
Hoopy frood
M

Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
i figured he was on about using fwrite as suppose to aline in the $findfile.

once listed using load and save buf to handle playlist speaks for itself smile


$maybe
Re: Can this be done faster? #132237
10/10/05 12:02 AM
10/10/05 12:02 AM
Joined: Apr 2003
Posts: 701
Leuven, Belgium
K
Kelder Offline
Hoopy frood
Kelder  Offline
Hoopy frood
K

Joined: Apr 2003
Posts: 701
Leuven, Belgium
How long does the original (non-hidden /aline) script take on those 112 files? Regardless, I may very well be wrong about the speed of /fwrite, disk access it always slow, so if Windows doesn't have a buffer, it can be way too slow.

Was thinking of using a hash table too, but there's no /loadbuf for it iirc.

For the record: no I didn't mean playlists or something like that... It's ofcourse way better than rescanning smile Just didn't think about it or found it irrelevant, dunno