mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
speed test for slow precedence issues
This commit is contained in:
@@ -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
|
||||
|
||||
37
test/speed/precedence.py
Normal file
37
test/speed/precedence.py
Normal file
@@ -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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user