-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deep2, deep3 lookup perf improvements
- deep2 creates item and attr getters - deep3 creates a func via eval 4 times speed improvements seen
- Loading branch information
Gunther Klessinger
committed
Feb 10, 2023
1 parent
54fea4c
commit 1ecb45a
Showing
10 changed files
with
749 additions
and
457 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
|
||
author: gk | ||
version: 20230211 | ||
version: 20230212 | ||
|
||
--- | ||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.ruff] | ||
line-length = 110 | ||
line-length = 90 | ||
ignore = ["E501", "E202"] | ||
|
||
[tool.blue] | ||
line-length = 110 | ||
line-length = 90 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import time | ||
from pycond import parse_cond | ||
|
||
_is = isinstance | ||
|
||
now = time.time | ||
|
||
|
||
def test_comp_perf(): | ||
"""6 times faster deep lookups when preassembled | ||
at first match | ||
""" | ||
now = time.time | ||
s = {'a': {'b': [{'c': 42}]}} | ||
|
||
class t: | ||
a = s | ||
|
||
# S = {'A': {'a': s}} | ||
S = {'A': t} | ||
|
||
count = 100000 | ||
|
||
def run(count=count, **kw): | ||
pc = parse_cond('A.a.a.b.0.c eq 42', **kw)[0] | ||
t0 = now() | ||
for i in range(count): | ||
assert pc(state=S) | ||
return now() - t0 | ||
|
||
dt1 = run(deep='.') | ||
dt2 = run(deep2='.') | ||
dt3 = run(deep3='.') | ||
print('Cached item getter perf vs get_deep:', dt1 / dt2) | ||
print('Eval perf vs get_deep:', dt1 / dt3) | ||
assert 2 * dt2 < dt1 | ||
|
||
|
||
if __name__ == '__main__': | ||
test_comp_perf() |
Oops, something went wrong.