Last active
August 29, 2015 14:27
-
-
Save livibetter/5307f068e584d5ed7703 to your computer and use it in GitHub Desktop.
Simple performance test on Universal Feed Parser (feedparser) and speedparser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Written by Yu-Jie Lin | |
# Placed in Public Domain | |
# Blog: http://blog.yjl.im/2015/08/speedparser-vs-feedparser-in-performance.html | |
from timeit import timeit | |
import feedparser as fp | |
import speedparser as sp | |
NUMBER = 3 | |
FILES = 100 | |
FEED_DIR = '/tmp/feeds' | |
SFP = 'import feedparser as fp' | |
SSP = 'import speedparser as sp' | |
G = ''' | |
def g(): | |
for i in range(1, {FILES}): | |
yield '{FEED_DIR}/%04d.dat' % (i + 1) | |
'''.format(FILES=FILES, FEED_DIR=FEED_DIR) | |
FP = ''' | |
for fn in g(): | |
r = fp.parse(fn) | |
''' | |
SP = ''' | |
for fn in g(): | |
with open(fn) as f: | |
r = sp.parse(f.read()) | |
''' | |
def test(m, version, stmt, setup): | |
FMT = ' %-11s (%5s): %7.3f seconds => %6.3f feeds / second' | |
t = timeit(stmt=stmt, setup=setup + G, number=NUMBER) | |
print(FMT % (m.__name__, version, t, FILES / t)) | |
def main(): | |
print('Benchmarking') | |
print(' %3d feeds' % FILES) | |
print(' %3d timeit runs' % NUMBER) | |
print('') | |
print('Results') | |
test(fp, fp.__version__, FP, SFP) | |
test(sp, '.'.join(map(str, sp.VERSION)), SP, SSP) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment