def things_main(ctx, db_url, solr_url, verbosity, heart_rate): ctx.ensure_object(dict) initialize_logging(verbosity) getLogger().info("Using database at: %s", db_url) ctx.obj["db_url"] = db_url getLogger().info("Using solr at: %s", solr_url) ctx.obj["solr_url"] = solr_url if heart_rate: heartrate.trace(browser=True)
# https://towardsdatascience.com/3-tools-to-track-and-visualize-the-execution-of-your-python-code-666a153e435e import heartrate heartrate.trace(browser=True) def factorial(x): if x == 1: return 1 else: return x * factorial(x - 1) if __name__ == "__main__": num = 5 print(f"The factorial of {num} is {factorial(num)}")
from hashlib import sha256 import snoop from loguru import logger from heartrate import trace trace(browser=True) class Block(): data, hash, nonce = None, None, 0 previous_hash = "0" * 64 def __init__(self, data, number=0): self.data, self.number = data, number def hash(self): data2hash, h = "", sha256() for arg in [self.previous_hash, self.number, self.data, self.nonce]: data2hash += str(arg) h.update(data2hash.encode("utf-8")) return h.hexdigest() def __str__(self): return f"Block: \t{self.number}\nHash: \t{self.hash()}\nPrevious: {self.previous_hash}\nNonce: \t{self.nonce}" class BlockChain(): difficulty = 4
def showtime(f, sub_f, name): start_time = time.time() f(sub_f) print("{} time: {:.4f}s".format(name, time.time() - start_time)) def main(sub_f): showtime(normal, sub_f, "normal") print() print("------ 多进程 ------") showtime(joblib_process, sub_f, "joblib multiprocess") showtime(mp, sub_f, "pool") showtime(asy, sub_f, "async") showtime(process_pool, sub_f, "process_pool") print() print("----- 多线程 -----") showtime(joblib_thread, sub_f, "joblib thread") showtime(thread, sub_f, "thread") showtime(thread_pool, sub_f, "thread_pool") if __name__ == "__main__": print("----- 计算密集型 -----") sub_f = f_compute heartrate.trace(main(sub_f)) print() print("----- IO 密集型 -----") sub_f = f_IO heartrate.trace(main(sub_f))
import heartrate; heartrate.trace(host='0.0.0.0',port='9011',browser=True) for i in range(0,4): print(i)