mpenning / ciscoconfparse2

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse2/
GNU General Public License v3.0
28 stars 7 forks source link

ciscoconfparse2 is slower than ciscoconfparse #2

Open mpenning opened 9 months ago

mpenning commented 9 months ago

Question

When parsing a large configuration such as tests/fixtures/configs/sample_06.ios and auto_commit=True, ciscoconfparse2 version 0.2.5 takes about 1.55 seconds on my system; however, parsing the same configuration with ciscoconfparse version 1.9.41 takes about 1.40 seconds.

sample_06.ios has over 4700 physical and virtual interfaces.

Why is ciscoconfparse2 about 10% slower?

try:
    # fail if we can't import ciscoconfparse2
    from ciscoconfparse2 import CiscoConfParse
except BaseException:
    from ciscoconfparse import CiscoConfParse

# auto_commit defaults True in ciscoconfparse2
parse = CiscoConfParse('tests/fixtures/configs/sample_06.ios', syntax='ios')

Answer:

This is due to the safety features that ciscoconfparse2 has; specifically it's due to the additional configuration safety built with in the ConfigList().get_checkpoint() method. get_checkpoint() is called with each commit() operation.

As of version 0.2.5, there are two big rocks that could chew up a lot of time:

Making ciscoconfparse2 significantly faster is a long-term improvement, if possible.