import time def get_all_lines(filename): start_time = time.time() try: f = open(filename, ‘rb‘) except Exception as e: exit(e) f.readlines() f.close() end_time = time.time() - start_time print("get_all_lines:%s" % end_time) def get_one_line(filename): start_time = time.time() try: f = open(filename, ‘rb‘) except Exception as e: exit(e) while True: string = f.readline() if not string: break f.close() end_time = time.time() - start_time print("get_one_line:%s" % end_time) if __name__ == ‘__main__‘: file_name = "des114.sql" get_all_lines(file_name) # 23.311237573623657 get_one_line(file_name) # 2.696101665496826
原文地址:https://www.cnblogs.com/yang-2018/p/10820811.html
时间: 2024-11-07 04:17:46