5
from os.path import splitext
7
LIST = ['truc.Mp3', 'foo', 'foo.OGG', 'Bidule.tXt', 'bar.vim', 'test.wav', 'hello.mp3', 'yeah.flac', 'dfsfdsa', 'dass.MPC', 'dfdsaaads.fsad']
12
mFormatsRE = re.compile('^.*\.(mp3|ogg|mpc|flac)$', re.IGNORECASE)
16
if mFormatsRE.match(word):
24
if w2.endswith('.mp3') or w2.endswith('.ogg') or w2.endswith('.mpc') or w2.endswith('.flac'):
30
for word in [w.lower() for w in LIST]:
31
if word.endswith('.mp3') or word.endswith('.ogg') or word.endswith('.mpc') or word.endswith('.flac'):
36
exts = set(['.mp3', '.ogg', '.mpc', '.flac'])
41
if w2[-4:] in exts or w2[-5:] in exts:
46
exts2 = {'.mp3': None, '.ogg': None, '.mpc': None, '.flac': None}
51
if w2[-4:] in exts2 or w2[-5:] in exts2:
58
if splitext(word)[1].lower() in exts2:
62
print 'Testing what is the extension of a given file'
64
t1 = timeit.Timer('re()', 'from __main__ import re')
65
t2 = timeit.Timer('ew()', 'from __main__ import ew')
66
t3 = timeit.Timer('ew_lc()', 'from __main__ import ew_lc')
67
t4 = timeit.Timer('ss_set()', 'from __main__ import ss_set')
68
t5 = timeit.Timer('ss_dic()', 'from __main__ import ss_dic')
69
t6 = timeit.Timer('ss_dic_split()', 'from __main__ import ss_dic_split')
71
print ' * regular expression:', t1.timeit(NB_ITERS)
72
print ' * endswith() 1: ', t2.timeit(NB_ITERS)
73
print ' * endswith() 2: ', t3.timeit(NB_ITERS)
74
print ' * substring + set: ', t4.timeit(NB_ITERS)
75
print ' * substring + dic: ', t5.timeit(NB_ITERS)
76
print ' * splitext() + dic: ', t6.timeit(NB_ITERS)