-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark.py
29 lines (21 loc) · 703 Bytes
/
benchmark.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
# pip install wordsegment
#
from wordseg import segment as wordseg
from wordsegment import segment
import timeit
def test_wordseg():
for hashtag in hdata:
wordseg(hashtag)
def test_wordsegment():
for hashtag in hdata:
segment(hashtag)
hdata = open('hashtags.txt').read().split()
n = 100
print("==wordseg==\t\t==wordsegment==")
for hashtag in hdata:
print("[" + " ".join(wordseg(hashtag)[0]) + "]\t\t[" + " ".join(segment(hashtag)) + "]")
print("==wordseg==\t\t==wordsegment==")
print(
str(timeit.timeit("test_wordseg()", number=n, setup="from __main__ import test_wordseg")) + "\t\t" +
str(timeit.timeit("test_wordsegment()", number=n, setup="from __main__ import test_wordsegment"))
)