Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import time
- import pyc
- ITERATIONS = 100000000
- iterative = xrange(ITERATIONS)
- def test():
- return None
- def calc_period_nsec(start, stop):
- return int(round(((stop - start) * 1e9) / ITERATIONS, 0))
- # measure no-load loop period:
- start = time.time()
- for _ in iterative:
- pass
- stop = time.time()
- period_noload = calc_period_nsec(start, stop)
- print 'no-load loop period:\t', period_noload, 'nsec'
- # now with C-invocation:
- start = time.time()
- for _ in iterative:
- pyc.test()
- stop = time.time()
- period_test_c = calc_period_nsec(start, stop)
- #print 'c loop period:\t', period_test_c, 'nsec'
- # and now with Python-invocation:
- start = time.time()
- for _ in iterative:
- test()
- stop = time.time()
- period_test_py = calc_period_nsec(start, stop)
- #print 'py loop period:\t', period_test_py, 'nsec'
- # ok, compute pure time and print it:
- pure_time_c = period_test_c - period_noload
- pure_time_py = period_test_py - period_noload
- print 'function invocation time [nsec]:'
- print 'c\t', pure_time_c
- print 'py\t', pure_time_py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement