Edit: Add an abstract of a file content
For multiple big files (> 10MB) stored as lists, I need to perform different match and capture
and use appropriate matched data with group().
I face performance issue doing this. Using re.compile() saves me a factor 3 but it is not enough.
Here is what I do for the moment:
import re
results = [
'EXTRACT for DC ANALYSIS',
' PARAM VREF = 1.0500E+00',
' TEMPERATURE = 2.5000E+01 Celsius',
' ICARLO = 9999',
' *VREF_INPUT = 1.0500E+00 Volts',
' *VREFSENSEANA = 2.1184E-01 Volts',
' *IREFCOMPANA = 1.7614E-05',
' *VOFFSET = 1.9432E-03 Volts',
' *IRATIO_COMP_PBIAS_DIFF__COMP_PIREFCOMP = 2.1124E+00',
' *IRATIO_COMP_PBIAS_OUT__COMP_PIREFCOMP = 1.0503E+00',
'',
'EXTRACT for DC TRANSFER CURVES',
' PARAM VREF = 1.0500E+00',
' TEMPERATURE = 2.5000E+01 Celsius',
' ICARLO = 10000',
' *VREF_INPUT = 1.0500E+00 Volts',
' *VREFSENSEANA = 2.1249E-01 Volts',
' *IREFCOMPANA = 1.6552E-05',
' *VOFFSET = 2.8657E-03 Volts',
' *IRATIO_COMP_PBIAS_DIFF__COMP_PIREFCOMP = 2.0130E+00',
' *IRATIO_COMP_PBIAS_OUT__COMP_PIREFCOMP = 1.0142E+00',
' *MC_501(VREF_INPUT) = 0.0',
' *MC_502(VREF_INPUT) = 1.0000E+00',
' *MC_600(VREF_INPUT) = 1.0500E+00',
' *MC_907(VREF_INPUT) = FAILED',
' *MC_908(VREF_INPUT) = 0.0',
]
re_analysis = re.compile(r'\s*EXTRACT for (\w+)')
re_param = re.compile(r'\s*PARAM\s+(\w+)\s*=\s*(\S+)')
re_alter = re.compile(r'\s*ALTER index (\d+)\s+(\w+)')
re_extract = re.compile(r'\s*\*(\w+)\s*=\s*(\S+)')
re_extract_mc = re.compile(r'\s*\*MC_(\d+)\((\w+)\)\s*=\s*(\S+)')
re_icarlo = re.compile(r'\s*ICARLO\s*=\s*(\d+)')
for line in results: # self.result is the file stored as list
match_analysis = re_analysis.match(line)
match_param = re_param.match(line)
match_alter = re_alter.match(line)
match_extract = re_extract.match(line)
match_extract_mc = re_extract_mc.match(line)
match_icarlo = re_icarlo.match(line)
# do some stuff with the various match and their group()
The overall process takes ~0.5sec on a given reference file, 0.35sec being the computations of the 6 match.
I wish to strongly reduce this 0.35sec match execution time.
Is there alternate ways to 'build' the 6 matches differently in order to be faster?
Or any other ways that do not use regex that could be faster?