Last active
May 10, 2020 10:06
-
-
Save bootjp/fb855cc4514bfeae17cb8b67975df297 to your computer and use it in GitHub Desktop.
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
import time | |
import re | |
def tail(thefile): | |
# thefile.seek(0, 2) | |
while True: | |
line = thefile.readline() | |
if not line: | |
time.sleep(0.5) | |
continue | |
line = line.rstrip("\n").rstrip("\r") | |
if line != "": | |
yield line | |
events = {"PlayerJoin": "[NetworkManager] OnPlayerJoined ", "PlayerLeft": "[NetworkManager] OnPlayerLeft ", | |
"EnterRoom": "[RoomManager] Entering Room: ", "ScreenShot": "Took screenshot to: "} | |
log_date_regex = re.compile( | |
"([0-9]{4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}) .*" | |
) | |
log_date_regex2 = re.compile( | |
"([0-9]{4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}) .*?" | |
) | |
def execute(line): | |
for event in events: | |
index = line.find(events[event]) | |
if index != -1: | |
body = line[index + len(events[event]):] | |
_ = log_date_regex.match(line).group(1), "\t" + event + ": " + body | |
def execute2(line): | |
for event in events: | |
index = line.find(events[event]) | |
if index != -1: | |
body = line[index + len(events[event]):] | |
_ = log_date_regex2.match(line).group(1), "\t" + event + ": " + body | |
# | |
def main(): | |
log_file = "/Users/bootjp/output_log_23-11-15.txt" | |
f = open(log_file, "r", encoding="utf-8") | |
# with open(log_file, "r", encoding="utf-8") as f: | |
lines = f.readlines() | |
for _ in range(3): | |
start = time.time() | |
for line in lines: | |
execute(line) | |
elapsed_time = time.time() - start | |
print("matching for .* elapsed_time:{0}".format(elapsed_time) + "[sec]") | |
start = time.time() | |
for line in lines: | |
execute2(line) | |
elapsed_time = time.time() - start | |
print("matching for .*? elapsed_time:{0}".format(elapsed_time) + "[sec]") | |
print("--") | |
f.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment