import logging import threading import time from log_module.log import logger_l2_process_time, logger_debug class TestInstance: __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance: cls.__instance = super(TestInstance, cls).__new__(cls, *args, **kwargs) print(cls.__instance) return cls.__instance def test(self): i=2 i+=1 _dict = {} def test_time(instance, i): start = time.time() instance.test() logger_debug.info(f"开始:{i}") time.time() # round(time.time() * 1000) - round(start * 1000) logger_debug.info(f"结束:{i}") if len(_dict.keys()) == 99: total = 0 for k in _dict: total += _dict[k] print(total / len(_dict)) if __name__ == "__main__": # for k in range(1): # _dict.clear() # for i in range(0, 100): # threading.Thread(target=lambda: test_time(TestInstance(), i), daemon=True).start() # time.sleep(2) print(time.time()) for i in range(1000): # logger_debug.debug("结束") TestInstance().test() pass print(time.time()) for i in range(1000): logger_debug.debug("结束") pass print(time.time()) input()