Re: Could this be faster?
- Posted by John Sas <jpsas at yahoo.com> Dec 14, 2005
- 561 views
C Bouzy wrote: > > Hi All, > > I am trying to speed up how I scan a audio folder and add it to a Playlist. > It works fast if there is only a few hundred files, but if there is 500 > or more files it can get to be slow. I scan the folder using walk_dir > and add each file into the database. Do any of you guys think I can do > this without using walk_dir? I have pasted a bit of the code below. > > > }}} <eucode> > function ScanDir(sequence path_name, sequence ItemEntry) > sequence addaudio,streamtime,filecount,filetitle > atom len,tempstream > > streamtime={} > addaudio={} > filecount={} > doEvents(0) > > > if equal(ItemEntry[D_ATTRIBUTES], "d") then ----If directory do nothing > > else > if match("aac", get_file_ext(lower(ItemEntry[D_NAME]))) or ---- If > supported file add to the Playlist > match("mp4", get_file_ext(lower(ItemEntry[D_NAME]))) or > match("mp3", get_file_ext(lower(ItemEntry[D_NAME]))) or > match("mp2", get_file_ext(lower(ItemEntry[D_NAME]))) or > match("mp1", get_file_ext(lower(ItemEntry[D_NAME]))) or > match("ogg", get_file_ext(lower(ItemEntry[D_NAME]))) or > match("wav", get_file_ext(lower(ItemEntry[D_NAME]))) > then > > tempstream = BASS_StreamCreateFile(0, path_name & "\\" & > ItemEntry[D_NAME], 0, 0, BASS_STREAM_AUTOFREE) ---Create a temp file to get the > file length > len = BASS_ChannelBytes2Seconds(tempstream, > BASS_ChannelGetLength(tempstream)) > streamtime = sprintf(" %d:%02d", {len / 60, > remainder(len, 60)}) > filetitle = get_file_title(ItemEntry[D_NAME]) > > if mdb_insert(appdir&"\\Playlist.dat","Playlist",convertCase(replace > (filetitle,"_"," ")),{path_name & "\\" & ItemEntry[D_NAME],streamtime}) > = -1 > then > else > addaudio &= addLVItem(Playlist,listicon2,{" > "&convertCase(replace (filetitle,"_"," "))," "&streamtime}) > end if > setIndex(Playlist, 1) > getCount() > end if > end if > doEvents(0) > return 0 > end function > </eucode> {{{ > > > VOID = walk_dir(audiofolder, routine_id("ScanDir"), 1) I don't think it is a problem with walk_dir. I can scan through 85,000 files and print the results to the screen (very costly) in about 72 sec. on an old 900MHz Intel PIII (should be a similar cost to inserting a record in your DB). Without printing the information on the screen, the files are scanned in about 2 sec. Your costs are most likely a bit higher because you open up a stream extract the play time and insert data into your database. I notice that you never close your temporary stream. I see that you have the "BASS_STREAM_AUTOFREE" flag set but I don't see a call to either BASS_ChannelStop() or BASS_Stop(). It appears to me that you are loading up your available memory with temporary streams and bogging down your system. John