#!/usr/bin/env python2.4 import resource def cpu(): return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ resource.getrusage(resource.RUSAGE_SELF).ru_stime) import hotshot, hotshot.stats prof = hotshot.Profile("main.prof") prof.start() import c1, c2 o1 = c1.C() o2 = c2.C() def f1(): o1.m() def f2(): o2.m() for j in xrange(2): t = cpu() for i in xrange(100000): f1() print ("python: %f s" % (cpu()-t)) t = cpu() for i in xrange(100000): f2() print ("pyrex: %f s" % (cpu()-t)) prof.stop() prof.close() stats = hotshot.stats.load("main.prof") stats.strip_dirs() stats.sort_stats('time', 'calls') stats.print_stats(100)