~mithunit/pogo/open-containing-folder

« back to all changes in this revision

Viewing changes to benchmarks/extension.py

  • Committer: François Ingelrest
  • Date: 2010-05-16 08:43:26 UTC
  • Revision ID: francois.ingelrest@gmail.com-20100516084326-sc82svgr51u1zyd0
* Initial import of Decibel 1.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os, re, timeit
 
4
 
 
5
from os.path import splitext
 
6
 
 
7
LIST     = ['truc.Mp3', 'foo', 'foo.OGG', 'Bidule.tXt', 'bar.vim', 'test.wav', 'hello.mp3', 'yeah.flac', 'dfsfdsa', 'dass.MPC', 'dfdsaaads.fsad']
 
8
NB_ITERS = 200000
 
9
 
 
10
# ---
 
11
 
 
12
mFormatsRE = re.compile('^.*\.(mp3|ogg|mpc|flac)$', re.IGNORECASE)
 
13
 
 
14
def re():
 
15
    for word in LIST:
 
16
        if mFormatsRE.match(word):
 
17
            pass
 
18
 
 
19
# ---
 
20
 
 
21
def ew():
 
22
    for word in LIST:
 
23
        w2 = word.lower()
 
24
        if w2.endswith('.mp3') or w2.endswith('.ogg') or w2.endswith('.mpc') or w2.endswith('.flac'):
 
25
            pass
 
26
 
 
27
# ---
 
28
 
 
29
def ew_lc():
 
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'):
 
32
            pass
 
33
 
 
34
# ---
 
35
 
 
36
exts = set(['.mp3', '.ogg', '.mpc', '.flac'])
 
37
 
 
38
def ss_set():
 
39
    for word in LIST:
 
40
        w2 = word.lower()
 
41
        if w2[-4:] in exts or w2[-5:] in exts:
 
42
            pass
 
43
 
 
44
# ---
 
45
 
 
46
exts2 = {'.mp3': None, '.ogg': None, '.mpc': None, '.flac': None}
 
47
 
 
48
def ss_dic():
 
49
    for word in LIST:
 
50
        w2 = word.lower()
 
51
        if w2[-4:] in exts2 or w2[-5:] in exts2:
 
52
            pass
 
53
 
 
54
# ---
 
55
 
 
56
def ss_dic_split():
 
57
    for word in LIST:
 
58
        if splitext(word)[1].lower() in exts2:
 
59
            pass
 
60
 
 
61
 
 
62
print 'Testing what is the extension of a given file'
 
63
 
 
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')
 
70
 
 
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)