Skip to content

Instantly share code, notes, and snippets.

@ls0f
Created August 15, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls0f/2b7e8543710d5d656764 to your computer and use it in GitHub Desktop.
Save ls0f/2b7e8543710d5d656764 to your computer and use it in GitHub Desktop.
python-count-time
#coding:utf-8
import time
__author = 'haifang'
def count_function_time():
def wraps(function):
function.CUR_TIME = time.time()
def log_time(point):
end_time = time.time()
spend_time = end_time - function.CUR_TIME
function.CUR_TIME = end_time
print "{} {} {:.3f}".format(function.__name__, point, spend_time)
function.log_time = log_time
return function
return wraps
@count_function_time()
def main():
main.log_time("point 1")
time.sleep(1)
main.log_time("point 2")
time.sleep(1.2)
main.log_time("point 3")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment