Skip to content

Instantly share code, notes, and snippets.

@minrk
Created June 1, 2012 01:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/2848007 to your computer and use it in GitHub Desktop.
Save minrk/2848007 to your computer and use it in GitHub Desktop.
import sys
import time
from subprocess import Popen, PIPE
def magic_pypy(line, cell):
cmd = ['pypy', '-c', cell]
tic = time.time()
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
p.wait()
toc = time.time()
out,err = p.communicate()
if err:
print >> sys.stderr, err
print out
if '-t' in line:
print "time: %.3fs" % (toc - tic)
get_ipython().register_magic_function(magic_pypy, 'cell', 'pypy')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment