[英]How do I test for speed with PyTest / tox?
For testing machine learning algorithms / repositories, I see three things that matter: 对于测试机器学习算法/存储库,我认为很重要的三件事:
While (1) and maybe (2) is standard unit testing, I'm not too sure how to deal with (3). 虽然(1)也许是(2)是标准单元测试,但我不太确定如何处理(3)。 Can I test this with pytest / tox?
我可以用pytest / tox测试吗?
I found pytest-benchmark
, but how would I do this for example for lidtk
? 我找到了
pytest-benchmark
,但是我将如何针对例如lidtk
呢?
In pseudo-code, I want to do the following: 用伪代码,我要执行以下操作:
def classifier_predict(input_features):
# do something smart, but maybe too time-consuming
return result
def input_generator():
# Generate something random which classifier_predict
# can work on - don't measure this time!
return input_features
class Agents(unittest.TestCase):
def test_classifier_predict():
self.assertMaxTime(classifier_predict,
input_generator,
max_time_in_ms=100)
Here is the pseudo-code of a rather hand-crafted solution: 这是一个手工制作的解决方案的伪代码:
def classifier_predict(input_features):
# do something smart, but maybe too time-consuming
return result
def input_generator():
# Generate something random which classifier_predict
# can work on - don't measure this time!
return input_features
class Agents(unittest.TestCase):
def test_classifier_predict():
nb_tests = 1000
total_time = 0.0
for _ in range(nb_tests):
input_ = input_generator()
t0 = time.time()
classifier_predict(input_)
t1 = time.time()
total_time += t1 - t0
self.assertLessEqual(total_time / nb_tests, 100)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.