Created
August 15, 2015 10:29
-
-
Save ls0f/2b7e8543710d5d656764 to your computer and use it in GitHub Desktop.
python-count-time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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