From 10809e836d0c45bcb3459f0146ed2937ea2ea7d5 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 24 Apr 2014 16:33:17 +0200 Subject: [PATCH] speed test for slow precedence issues --- pytest.ini | 2 +- test/speed/precedence.py | 37 +++++++++++++++++++++++++++++++++++++ test/test_speed.py | 15 +++++++++++++-- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 test/speed/precedence.py diff --git a/pytest.ini b/pytest.ini index 0d73061d..9b23b845 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,7 +2,7 @@ addopts = --doctest-modules # Ignore broken files in blackbox test directories -norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions +norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed # Activate `clean_jedi_cache` fixture for all tests. This should be # fine as long as we are using `clean_jedi_cache` as a session scoped diff --git a/test/speed/precedence.py b/test/speed/precedence.py new file mode 100644 index 00000000..5f0c9144 --- /dev/null +++ b/test/speed/precedence.py @@ -0,0 +1,37 @@ +def whatever(code): + if '.' in code: + another(code[:code.index('.') - 1] + '!') + else: + another(code + '.') + + +def another(code2): + call(ret(code2 + 'haha')) + +whatever('1.23') +whatever('1,23') + + +def ret2(code4): + if 1: + if 2: + return code4 + 'i' + else: + return code4 + 'k' + else: + if 2: + return code4 + 'l' + else: + return code4 + 'h' + + +def ret(code5): + if 2: + return ret2(code5 + 'r') + else: + return ret2(code5 + 'k') + + +def call(code3): + code3 = '1' + ret(code3) + code3.partition diff --git a/test/test_speed.py b/test/test_speed.py index 78fb10ad..be39cc08 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -6,7 +6,7 @@ should. import time import functools -from .helpers import TestCase +from .helpers import TestCase, cwd_at import jedi class TestSpeed(TestCase): @@ -25,7 +25,7 @@ class TestSpeed(TestCase): func(self) single_time = (time.time() - first) / number print('\nspeed', func, single_time) - assert single_time < time_per_run + assert single_time < time_per_run, 'Too slow.' return wrapper return decorated @@ -40,3 +40,14 @@ class TestSpeed(TestCase): script = jedi.Script(s, 1, len(s), '') script.call_signatures() #print(jedi.imports.imports_processed) + + @_check_speed(0.1) + @cwd_at('test') + def test_precedence_slowdown(self): + """ + Precedence calculation can slow down things significantly in edge + cases. Having strange recursion structures increases the problem. + """ + with open('speed/precedence.py') as f: + line = len(f.read().splitlines()) + assert jedi.Script(line=line, path='speed/precedence.py').goto_definitions()