forked from VimPlug/jedi
add a separate speed testing file, #181
This commit is contained in:
37
test/test_speed.py
Normal file
37
test/test_speed.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import time
|
||||
import functools
|
||||
|
||||
from .base import unittest
|
||||
import jedi
|
||||
|
||||
class TestSpeed(unittest.TestCase):
|
||||
def _check_speed(time_per_run, number=4, run_warm=True):
|
||||
""" Speed checks should typically be very tolerant. Some machines are
|
||||
faster than others, but the tests should still pass. These tests are
|
||||
here to assure that certain effects that kill jedi performance are not
|
||||
reintroduced to Jedi."""
|
||||
def decorated(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(self):
|
||||
if run_warm:
|
||||
func(self)
|
||||
first = time.time()
|
||||
for i in range(number):
|
||||
func(self)
|
||||
single_time = (time.time() - first) / number
|
||||
print('\nspeed', func, single_time)
|
||||
assert single_time < time_per_run
|
||||
return wrapper
|
||||
return decorated
|
||||
|
||||
@_check_speed(0.2)
|
||||
def test_os_path_join(self):
|
||||
s = "from posixpath import join; join('', '')."
|
||||
assert len(jedi.Script(s).completions()) > 10 # is a str completion
|
||||
|
||||
@_check_speed(0.1)
|
||||
def test_scipy_speed(self):
|
||||
s = 'import scipy.weave; scipy.weave.inline('
|
||||
script = jedi.Script(s, 1, len(s), '')
|
||||
script.call_signatures()
|
||||
#print(jedi.imports.imports_processed)
|
||||
Reference in New Issue
Block a user