Created
February 7, 2011 04:51
-
-
Save eyeseast/814011 to your computer and use it in GitHub Desktop.
Download the last 10 entries from my blog, with or without gevent
This file contains 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 | |
# encoding: utf-8 | |
""" | |
greenparser.py | |
A simple test script to measure the difference between | |
regular urllib2 downloads and gevent-based downloads. | |
""" | |
from gevent import monkey | |
monkey.patch_socket() | |
import feedparser | |
import gevent | |
import sys | |
import os | |
import urllib2 | |
def parse_entry(entry): | |
body = urllib2.urlopen(entry.link).read() | |
print entry.title, len(body) | |
def main(): | |
parsed = feedparser.parse('http://chrisamico.com/feeds/blog/') | |
jobs = [gevent.spawn(parse_entry, entry) for entry in parsed.entries] | |
gevent.joinall(jobs) | |
if __name__ == '__main__': | |
main() |
This file contains 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 | |
# encoding: utf-8 | |
""" | |
parser.py | |
""" | |
import feedparser | |
import sys | |
import os | |
import urllib2 | |
def main(): | |
parsed = feedparser.parse('http://chrisamico.com/feeds/blog/') | |
for entry in parsed.entries: | |
body = urllib2.urlopen(entry.link).read() | |
print entry.title, len(body) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so which one's faster?