mIRC Home    About    Download    Register    News    Help

Print Thread
#72243 21/02/04 07:21 AM
Joined: Jan 2004
Posts: 26
M
module Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Jan 2004
Posts: 26
I've tried so many methods of optimizing my mp3 script which uses a hashtable to store the file and it's mpeg properties. I use a dll for gathering mpeg info and if the dll fails which occurrs sometimes, then i use mircs $sound to retreive the information. I'm not really worried about it, just ideas and suggestions would be nice because of now whenever making the database i go through a process before the actual creation. I have the script read from the hashtable that is currently loaded and check if the entries within the hashtable exists as files within the mp3 directory. I'd just like to speed up the process of the actual creation time for new databases. Thanks.
I have 1500+ mp3s so the creation time takes about one minute, which isn't bad but i'm picky, lol.


It's not in the GUI, it's in the source.
#72244 21/02/04 07:55 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
are you displaying any form of loop counter or progress counter during the creation ?

#72245 21/02/04 09:43 AM
Joined: Jan 2004
Posts: 26
M
module Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Jan 2004
Posts: 26
Not any type of counters just one loop to read through the .txt which is created for the mp3 directory list. Here's the current code I'm using:
alias mp3db.make {
if (!$hget(mp3)) { ^mp3_load_db }
if ($hget(mp3,0).item == $findfile($sound(mp3),*.mp?,0)) {
echo -s -> MP3 DB is up-to-date.
return
}
echo -s -> Updating mp3 database...
var %ticks $ticks, %a, %b, %str, %idx 0, %temp, %mpeg
_mp3dirlist
while (%idx < $lines(myoutput.txt)) {
inc %idx
%temp = $read(myoutput.txt, nl, %idx)
if ($isfile($gettok(%temp,1,32))) {
if (!$hget(mp3,$gettok(%temp,1,32))) {
%a = $gettok(%temp,1,32)
%b = $gettok(%temp,2,32)
%mpeg = $mpeginfo(%a)
tokenize 32 %mpeg
%str = $+($1,$chr(9),$2,$chr(9),$3,$chr(9),$4-,$chr(9),$lower($bytes(%b).suf))
.hadd mp3 %a %str
}
}
}
.hsave -ob mp3 $scriptdirmp3.db
.remove myoutput.txt
echo -s -> MP3 database updated in $:ms(%ticks) seconds.
}


It's not in the GUI, it's in the source.
#72246 21/02/04 10:44 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
try this.

Code:
 
alias mp3db.make {
  if (!$hget(mp3)) { ^mp3_load_db }
  if ($hget(mp3,0).item == $findfile($sound(mp3),*.mp?,0)) {
    echo -s -&gt; MP3 DB is up-to-date.
    return
  }
  echo -s -&gt; Updating mp3 database...
  var %ticks $ticks, %a, %b, %str, %idx 0, %temp, %mpeg
  _mp3dirlist
  if ($fopen(myoutput) != $null) fclose myoutput
  fopen myoutput myoutput.txt
  if ($ferr == 0) {
    while ($ferr == 0 &amp;&amp; $feof == 0) {
      %temp = $fread(myoutput)
      if ($isfile($gettok(%temp,1,32))) {
        if (!$hget(mp3,$gettok(%temp,1,32))) {
          %a = $gettok(%temp,1,32)
          %b = $gettok(%temp,2,32)
          %mpeg = $mpeginfo(%a)
          tokenize 32 %mpeg
          %str = $+($1,$chr(9),$2,$chr(9),$3,$chr(9),$4-,$chr(9),$lower($bytes(%b).suf))
          .hadd mp3 %a %str
        }
      }
    }
    if ($ferr == 0) {
       if ($fopen(myoutput) != $null) fclose myoutput
      .hsave -ob mp3 $scriptdirmp3.db
      .remove myoutput.txt
      echo -s -&gt; MP3 database updated in $:ms(%ticks) seconds.
    }
  }
  if ($fopen(myoutput) != $null) fclose myoutput
}
 

as thats only a subsection of your code i couldnt run it to test it but i think it looks right.

Here is some things that take up time I changed.

>> while (%idx < $lines(myoutput.txt)) {
the identifier $lines(myoutput.txt) reads the said file from front to end counting the number of lines in it, you do this once per line so you just for the WHILE condition read the file as many times as there are lines in it.

>>%temp = $read(myoutput.txt, nl, %idx)
the identifier $read(myoutput.txt, nl, %idx) reads the said file from front to the line requested, you do this once per line so you read 1/2 the file on average every $READ


What I have done is instead
(1) open the file
(2) check if its at the end of the file ($feof)
(3) if not then read the line im at, process it, then loop back to (2)
(4) finsih up

this well cause one file read, rather than 1.5 entire reads of the file per line processed.


You might consider doing this, but i doubt you well get more than a second per 10,000 lines
>> tokenize 32 $chr(9) %mpeg
>> %str = $+($2,$1,$3,$1,$4,$1,$5-,$1,$lower($bytes(%b).suf))

OR (not and) at the start of the alias adding
>>var %tab = $chr(9)
and making the two lines above like this.
>>tokenize 32 %mpeg
>>%str = $+($1,%tab,$2,%tab,$3,%tab,$4-,%tab,$lower($bytes(%b).suf))

but again i doubt much performance increase on that.


#72247 21/02/04 10:57 AM
Joined: Jan 2004
Posts: 26
M
module Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Jan 2004
Posts: 26
Thanks appreciate the help. Going to try it right now.


It's not in the GUI, it's in the source.

Link Copied to Clipboard