forked from seomoz/reppy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench.py
executable file
·53 lines (42 loc) · 1.09 KB
/
bench.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
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env python
from __future__ import print_function
from contextlib import contextmanager
import sys
import time
from reppy.robots import Robots
content = '''
# /robots.txt for http://www.fict.org/
# comments to [email protected]
User-agent: unhipbot
Disallow: /
User-agent: webcrawler
User-agent: excite
Disallow:
User-agent: *
Disallow: /org/plans.html
Allow: /org/
Allow: /serv
Allow: /~mak
Disallow: /
'''
@contextmanager
def timer(name, count):
'''Time this block.'''
start = time.time()
try:
yield count
finally:
duration = time.time() - start
print(name)
print('=' * 10)
print('Total: %s' % duration)
print(' Avg: %s' % (duration / count))
print(' Rate: %s' % (count / duration))
print('')
with timer('Parse', 100000) as count:
for _ in xrange(count):
Robots.parse('http://example.com/robots.txt', content)
parsed = Robots.parse('http://example.com/robots.txt', content)
with timer('Evaluate', 100000) as count:
for _ in xrange(count):
parsed.allowed('/org/example.html', 'other-bot')