Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize apply_templates #20

Merged
merged 1 commit into from
Jan 24, 2016
Merged

Optimize apply_templates #20

merged 1 commit into from
Jan 24, 2016

Conversation

bheinzerling
Copy link
Contributor

Recomputing range(len(X)) for every iteration inside the loop is not necessary, because len(X) is invariant. Furthermore, using lists for membership testing (line 28 in the old version) is O(n), while it is O(1) for sets.

Testing with a sequence of ~46k items, the new code is about 8 times faster on my machine. Diffing the output of the new version and the old version showed that the outputs are the same.

Recomputing range(len(X)) for every iteration inside the loop is not necessary, since len(X) is invariant. Furthermore, using lists for membership testing (line 32) is O(n), while it is O(1) for sets.

Testing with a sequence of ~46k items, the new code is about 8 times faster on my machine. Diffing the output of the new version and the old version showed that the outputs are the same.
chokkan pushed a commit that referenced this pull request Jan 24, 2016
Optimize apply_templates (also close #49)
@chokkan chokkan merged commit d3d4040 into chokkan:master Jan 24, 2016
@bheinzerling bheinzerling deleted the patch-1 branch January 25, 2016 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants