On Tue, Dec 5, 2017, 7:13 AM Gabriel Forster <gabejessfors...@gmail.com>
wrote:

> As far as I understand, that perl line is by far the fastest way to delete
> files in linux.  We're talking over 500k files on hdd.
>

It may be the 500k stats that are killing you. From the looks of your code,
the stat seems unnecessary as you only use it to get the file name. Can you
switch to Readdirnames() and see how that goes?


> On Monday, December 4, 2017 at 12:50:54 PM UTC-5, Gabriel Forster wrote:
>
>> What takes 18 seconds in a perl command:
>> perl -e 'for(<*>){((stat)[9]<(unlink))}'
>>
>> is taking almost 8 minutes with the following code. Any ideas how I can
>> speed this up?
>>
>> dir, err := os.Open("/var/spool/directory")
>>         if err != nil {
>>                 fmt.Fprintf(w, "failed - " + err.Error())
>>                 return
>>         }
>>         defer dir.Close()
>>
>>
>>         files, err := dir.Readdir(-1)
>>         if err != nil {
>>                 fmt.Fprintf(w, "failed - " + err.Error())
>>                 return
>>         }
>>
>>         for _, file := range files {
>>                 if file.Name() == "." || file.Name() == ".." {
>>                         continue
>>                 }
>>
>>                 os.Remove("/var/spool/directory/" + file.Name())
>>         }
>>
>>
>>         fmt.Fprintf(w, "success")
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to