The speed of glob()

Gisle Vanem gisle.vanem at gmail.com
Wed Jul 29 04:26:25 EDT 2020


Has anybody noticed the speed of 'glob()' has
decreased somewhere between v3.6 and v3.10.
With this little test:

------------
import os, sys, timeit, glob

# change to suite
globPath = u'e:/net/*/*/*/*'

def _glob():
   glob.glob (globPath)

# I used this 'https://docs.microsoft.com/en-gb/sysinternals/downloads/sync'
def flush_disks():
   sync = r"f:\ProgramFiler\Sysinternals\sync.exe -nobanner"
   print ("Exec sync: %s" % sync)
   os.system (sync)

flush_disks()
print ("Python %d.%d.%d:" % sys.version_info[:3])
print ("  1st run: %.5f" % timeit.timeit (_glob, number=1))
print ("  2nd run: %.5f" % timeit.timeit (_glob, number=1))

------------

I got these results:
   Python 3.6.5:
     1st run: 0.14694
     2nd run: 0.09506   <- *always* the fastest
   Python 3.7.7:        <- from Nuget
     1st run: 0.12440
     2nd run: 0.09602
   Python 3.10.0:       <- from Git repo
     1st run: 0.15922
     2nd run: 0.12424

'glob()' in Python 3.6.5 is consistently 30% faster on
the 2nd run compared to 3.10.0.

-- 
--gv


More information about the Python-list mailing list