Skip to content

Instantly share code, notes, and snippets.

@tunelessly
Created April 27, 2025 22:57
Show Gist options
  • Save tunelessly/11c2d1af3e3c90ed34d56adb0cbe7d04 to your computer and use it in GitHub Desktop.
Save tunelessly/11c2d1af3e3c90ed34d56adb0cbe7d04 to your computer and use it in GitHub Desktop.
import timeit
import re
from filewatcher.logparser import (
parseLine as parseLineNew,
EventType as EventTypeNew,
combatLinePattern as combatLinePatternNew,
)
from filewatcher.logparser2 import (
parseLine as parseLineOld,
EventType as EventTypeOld,
combatLinePattern as combatLinePatternOld,
)
charNameLine = "Listener: ChrySsin"
combatLine = "[ 2023.12.02 21:54:11 ] (combat) <color=0xffe57f7f><b>0 GJ</b><color=0x77ffffff><font size=10> energy neutralized </font><b><color=0xffffffff>Starving Leshak</b><color=0x77ffffff><font size=10> - Starving Leshak</font>"
capSentLine = "[ 2024.06.22 20:45:31 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote capacitor transmitted to </font><b><color=0xffffffff><font size=12><color=0xFFFFB900> <u><b>Basilisk</b></u></color></font><font size=12><color=0xFFFEFF6F> [<b>KYBER</b>]</color></font> [<b>CLKYB</b>] [Kimball Sky]<color=0xFFFFFFFF><b> -</b><color=0x77ffffff><font size=10> - Large Inductive Compact Remote Capacitor Transmitter</font>"
capReceivedLine = "[ 2024.06.22 20:45:29 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote capacitor transmitted by </font><b><color=0xffffffff><font size=12><color=0xFFFFB900> <u><b>Basilisk</b></u></color></font> [Bradley Johannson]<color=0xFFFFFFFF><b> -</b><color=0x77ffffff><font size=10> - Large Inductive Compact Remote Capacitor Transmitter</font>"
shieldSentLine = "[ 2024.06.22 20:34:44 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote shield boosted to </font><b><color=0xffffffff><font size=12><color=0xFFFFB900> <u><b>Basilisk</b></u></color></font> [Bradley Johannson]<color=0xFFFFFFFF><b> -</b><color=0x77ffffff><font size=10> - Large Murky Compact Remote Shield Booster</font>"
shieldReceivedLine = "[ 2024.06.22 20:34:21 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote shield boosted by </font><b><color=0xffffffff><font size=12><color=0xFFFFB900> <u><b>Basilisk</b></u></color></font> [Bradley Johannson]<color=0xFFFFFFFF><b> -</b><color=0x77ffffff><font size=10> - Large Remote Shield Booster II</font>"
dpsSentLine = "[ 2023.11.18 01:12:37 ] (combat) <color=0xff00ffff><b>1002</b> <color=0x77ffffff><font size=10>to</font> <b><color=0xffffffff>Harrowing Vedmak</b><font size=10><color=0x77ffffff> - Imperial Navy Infiltrator - Penetrates"
dpsReceivedLine = "[ 2023.10.08 17:34:33 ] (combat) <color=0xffcc0000><b>983</b> <color=0x77ffffff><font size=10>from</font> <b><color=0xffffffff>Karybdis Tyrannos</b><font size=10><color=0x77ffffff> - Penetrates"
armorSentLine = "[ 2025.03.23 15:53:57 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote armor repaired to </font><b><color=0xffffffff><font size=10><color=0xFFFF9F40>Magus</color></font><font size=9>[Cynreth Falkenwacht] -</font></b><color=0x77ffffff><font size=10> - Corelum A-Type Medium Remote Armor Repairer</font>"
armorReceivedLine = "[ 2025.03.23 15:53:46 ] (combat) <color=0xffccff66><b>0</b><color=0x77ffffff><font size=10> remote armor repaired by </font><b><color=0xffffffff><font size=10><color=0xFFFF9F40>Guardian</color></font><font size=9>[D'Avore] -</font></b><color=0x77ffffff><font size=10> - Medium Remote Armor Repairer II</font>"
neutReceivedLine = "[ 2024.06.22 20:32:35 ] (combat) <color=0xffe57f7f><b>137 GJ</b><color=0x77ffffff><font size=10> energy neutralized </font><b><color=0xffffffff>Elite Imperial Navy Armageddon</b><color=0x77ffffff><font size=10> - Elite Imperial Navy Armageddon</font>"
neutSentLine = "[ 2024.08.18 22:22:34 ] (combat) <color=0xff7fffff><b>0 GJ</b><color=0x77ffffff><font size=10> energy neutralized </font><b><color=0xffffffff><font size=12><color=0xFFFFB300> <u><b>Capsule</b></u></color></font><font size=12><color=0xFFFFFF66> [<b>BIGAB</b>]</color></font> [Whorehowl]<color=0xFFFFFFFF><b> -</b><color=0x77ffffff><font size=10> - True Sansha Small Energy Neutralizer</font>"
lines = [
combatLine,
capSentLine,
capReceivedLine,
shieldSentLine,
shieldReceivedLine,
dpsSentLine,
dpsReceivedLine,
armorSentLine,
armorReceivedLine,
]
lines_events = {
"DPS_SENT": dpsSentLine,
"GUN_DPS_SENT": dpsSentLine,
"DRONE_SENT": dpsSentLine,
"DPS_RECEIVED": dpsReceivedLine,
"GUN_DPS_RECEIVED": dpsReceivedLine,
"DRONE_RECEIVED": dpsReceivedLine,
"SHIELD_RECEIVED": shieldReceivedLine,
"SHIELD_SENT": shieldSentLine,
"ARMOR_RECEIVED": armorReceivedLine,
"ARMOR_SENT": armorSentLine,
"CAP_RECEIVED": capReceivedLine,
"CAP_SENT": capSentLine,
"NEUT_RECEIVED": neutReceivedLine,
"NEUT_SENT": neutSentLine,
"LOGI_RECEIVED": armorReceivedLine,
"LOGI_SENT": armorSentLine,
}
event_names = [event.name for event in EventTypeOld]
event_values_old = [EventTypeOld[event].value for event in event_names]
event_values_new = [EventTypeNew[event].value for event in event_names]
zipped_events = list(zip(event_values_old, event_values_new))
events_the_eventening = {}
for index, event in enumerate(event_names):
events_the_eventening[event] = (lines_events[event],) + zipped_events[index]
iterations = 1000
def old():
for line in lines:
parseLineOld("test", line)
def new():
for line in lines:
parseLineNew("test", line)
results_old = timeit.repeat(
old,
number=iterations,
)
results_old_min = min(results_old)
results_old_max = max(results_old)
print(f"old method results global")
print(f"old: min {results_old_min / iterations}s max {results_old_max / iterations}s")
results_new = timeit.repeat(
new,
number=iterations,
)
results_new_min = min(results_new)
results_new_max = max(results_new)
print(f"new method results global")
print(f"new: min {results_new_min / iterations}s max {results_new_max / iterations}s")
def both(iterations):
for event_name, event_data in events_the_eventening.items():
event_line = event_data[0]
EventDefOld = event_data[1]
EventDefNew = event_data[2]
results_old_min = 0
results_new_min = 0
print(f"Handling {event_name}")
for pattern in EventDefOld.patterns:
results_old = timeit.repeat(
lambda: re.search(pattern, event_line),
number=iterations,
)
print(
f"re.search {event_name} {pattern}: min {min(results_old) / iterations}s max {max(results_old) / iterations}s"
)
results_old_min = min(results_old)
for pattern in EventDefNew.patterns:
results_new = timeit.repeat(
lambda: pattern.search(event_line),
number=iterations,
)
print(
f"compile.search {event_name} {pattern}: min {min(results_new) / iterations}s max {max(results_new) / iterations}s"
)
results_new_min = min(results_new)
print(f"speedup: {1/(results_new_min / results_old_min)} x")
both(200000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment