Ding ding ding! We have a winner! Thank you so much. That made a huge difference. It is now running ~20 seconds.
The key is being in the same directory. On Monday, December 4, 2017 at 2:17:03 PM UTC-5, Patrick Smith wrote: > > Does it make a difference if you first change directory to > /var/spool/directory, then glob * and unlink the resulting filenames, > without prepending the directory? > > On Mon, Dec 4, 2017 at 11:05 AM, Gabriel Forster <gabejes...@gmail.com > <javascript:>> wrote: > >> Readdirnames wasn't much better. Now using globbing and syscall.Unlink >> which take ~1minute 30seconds. It is much better, but still a long way from >> perl's sub-20 seconds. >> >> package main >> >> import ( >> "fmt" >> "path/filepath" >> "syscall" >> ) >> >> func main() { >> >> upperDirPattern := "/var/spool/directory/*" >> matches, err := filepath.Glob(upperDirPattern) >> >> if err != nil { >> fmt.Println(err) >> } >> >> for _, file := range matches { >> syscall.Unlink(file) >> } >> } >> >> >> >> 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...@googlegroups.com <javascript:>. >> 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.