1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| from timeit import Timer
ch = "h1n1_brr<hu&Aity998y che9m 3:::::897 ghrity,46kilo per=<"
patA = re.compile('\t*\w+<([^<]+)')
patB = re.compile('\t*\w+<(.+)<')
patI = re.compile('\t*\w+<(.{4}(i.?y) {0,12}[^123456]+.:+\d{3} ghr\\2[,"](?!8)\d+kil. +[eoirnp=x]{3,5})<')
tA = Timer('x = patA.match(ch).group(1)','from __main__ import patA,ch').repeat(5000,10)
tB = Timer('x = patB.match(ch).group(1)','from __main__ import patB,ch').repeat(5000,10)
tI = Timer('x = patI.match(ch).group(1)','from __main__ import patI,ch').repeat(5000,10)
minA = min(tA)
minB = min(tB)
minI = min(tI)
print 'avec [^%] dans RE :',minA
print 'avec .+ dans RE :',minB,'....',str(minB*100/minA)[0:6],'%'
print 'avec RE detaillee :',minI,'....',str(minI*100/minA)[0:6],'%'
resA = patA.match(ch).group(1)
resB = patB.match(ch).group(1)
resI = patI.match(ch).group(1)
print 'resI == resA : ',resI==resA,'\nresI == resB : ',resI==resB |
Partager