-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
39 lines (25 loc) · 831 Bytes
/
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
from __future__ import print_function
from timeit import timeit
from humanname import Name
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
url = "https://raw.githubusercontent.com/djudd/human-name/master/tests/benchmark-names.txt" # noqa
names = urlopen(url).read().splitlines()
def parse_all():
for string in names:
n = Name.parse(string)
if n is not None:
n.surname
t = timeit(parse_all, number=25)
print("Parsing %d names 25 times (humanname): %fs" % (len(names), t))
try:
from nameparser import HumanName
except ImportError:
exit(0)
def parse_all_nameparser():
for string in names:
HumanName(string).last
t = timeit(parse_all, number=25)
print("Parsing %d names 25 times (nameparser): %fs" % (len(names), t))