New submission from Dennis Sweeney <sweeney.dennis...@gmail.com>:
This patch ensures keyword-passing happens in linear time, fulfilling the 26-year-old TODO comment in ceval.c: XXX speed up searching for keywords by using a dictionary from time import perf_counter from itertools import repeat def bench(N): reps = 1 + 10_000_000 // N kwargs = {"a"*i: None for i in range(1, N+1)} param_list = ",".join(kwargs) function = eval(f"lambda {param_list}: 17") t0 = perf_counter() for _ in repeat(None, reps): result = function(**kwargs) t1 = perf_counter() assert result == 17 return (t1 - t0) / reps for i in list(range(1, 11)) + [20, 50, 100, 200, 500, 1000]: print(f"{i} --> {bench(i):.2e}") before: 1 --> 1.73e-07 2 --> 2.22e-07 3 --> 2.57e-07 4 --> 3.25e-07 5 --> 3.93e-07 6 --> 4.87e-07 7 --> 5.92e-07 8 --> 7.02e-07 9 --> 8.40e-07 10 --> 9.59e-07 20 --> 3.11e-06 50 --> 1.49e-05 100 --> 5.61e-05 200 --> 2.21e-04 500 --> 1.29e-03 1000 --> 5.09e-03 after: 1 --> 1.78e-07 2 --> 2.14e-07 3 --> 2.37e-07 4 --> 2.63e-07 5 --> 2.87e-07 6 --> 3.31e-07 7 --> 3.41e-07 8 --> 3.66e-07 9 --> 3.84e-07 10 --> 4.17e-07 20 --> 8.17e-07 50 --> 1.77e-06 100 --> 3.66e-06 200 --> 8.10e-06 500 --> 2.82e-05 1000 --> 7.95e-05 ---------- components: Interpreter Core messages: 393828 nosy: Dennis Sweeney priority: normal severity: normal status: open title: speed up searching for keywords by using a dictionary type: performance versions: Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44160> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com