Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created February 7, 2011 04:51
Show Gist options
  • Select an option

  • Save eyeseast/814011 to your computer and use it in GitHub Desktop.

Select an option

Save eyeseast/814011 to your computer and use it in GitHub Desktop.
Download the last 10 entries from my blog, with or without gevent
#!/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()
#!/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()
@choicio

choicio commented Jan 7, 2014

Copy link
Copy Markdown

so which one's faster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment