-
Notifications
You must be signed in to change notification settings - Fork 1
/
regex.py
43 lines (35 loc) · 969 Bytes
/
regex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import re
import mmap
import os
import time
'''Trying out regex on mmap files'''
FILE_NAME = 'C:\Users\Fruch\Dropbox\Python\sub\sub.log'
lines = 0
def mapcount(filename, end):
global lines
readline = m.readline
lines += 1
while readline():
if m.tell() > end: break
lines += 1
return lines
f = open(FILE_NAME)
m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
file_size = os.path.getsize(FILE_NAME)
regex = re.compile('\[(?P<date>.*?[^\]])\]DEBUG(?P<line>.*?)\n')
print file_size
start_time = time.time()
for match in regex.finditer(m):
start = match.start()
linenum = mapcount(FILE_NAME, start)
#print percentage
#print match.group('date')
print time.time() - start_time
start_time = time.time()
linenum = mapcount(FILE_NAME, file_size)
for num, line in enumerate(f):
match = regex.match(line)
if match:
start = match.start()
#print num, match
print time.time() - start_time