Captured output slows down tests a lot #230
Replies: 7 comments
-
@sk- More details, please!
|
Beta Was this translation helpful? Give feedback.
-
Operating System: macOS Catalina 10.15.4 The following file reproduces the problem: import unittest
import parameterized
class GreenTest(unittest.TestCase):
@parameterized.parameterized.expand([[i] for i in range(1000)])
def test_speed(self, a):
print('testing...')
self.assertGreaterEqual(a, 0) GreenWithout print: Python runnerWithout print: |
Beta Was this translation helpful? Give feedback.
-
Perfect! That's very useful info. |
Beta Was this translation helpful? Give feedback.
-
I'm curious if this project might do |
Beta Was this translation helpful? Give feedback.
-
Also important to note is the fact that the runner, even without captured output seems to be about 17x slower compared to python's unittest runner. Could it be that there's a noticeable overhead introduced by using multiple processes? With more complex test suites I still see a slowdown of about 4x. But maybe my tests are still to fast to get a performance advantage by using multiprocesses. If I use green with the option |
Beta Was this translation helpful? Give feedback.
-
No, green does not support that currently. |
Beta Was this translation helpful? Give feedback.
-
@sk- By default, entire test modules are given to a single sub-process to test. The only exception is if you specify specific classes or methods to test on the command-line. So the performance gains from green come from having enough modules to spread among several subprocesses. Green itself uses unittest under the hood. That approach is a blessing and a curse. The advantage is that green doesn't invent any new test framework stuff and just uses unittest for a lot of the actual work. The disadvantage is everything green does is on top of unittest, so there's a bunch of overhead. There's the fixed overhead of launching some number of subprocesses. There's the mostly-fixed overhead of loading all the code to be tested (it's almost always loaded exactly twice - once by the main process and once by the process that actually runs the tests). Then there's the highly-variable overhead of whatever we add on top of the regular functionality--like intercepting output. The whole point of Green was to make output nice, so we do a lot of extra work on anything we output in our output handling. Although it would be nice to be more optimized, it's not a common problem that folks have with green, so I don't consider this a bug. My advice would be "don't print so much stuff!" Having said that, I would be more than happy to accept any pull requests people make to optimize the performance of green! To that end, I've marked this issues as |
Beta Was this translation helpful? Give feedback.
-
First of all I wanted to say that I recently started using
green
, and it's great, I'm really happy with it.However, I noticed that when a test prints to
stdout
, the tests becomes super slow.Here are some timings:
Without any
print
s:Ran 731 tests in 0.644s using 4 processes
Adding a
print('test')
:Ran 731 tests in 3.856s using 4 processes
Adding a
print('test')
and running withgreen -q
:Ran 731 tests in 4.057s using 4 processes
which is almost 6 times slower than when there's no output.
Any idea what the problem may be? Or how to provide some extra details.
Beta Was this translation helpful? Give feedback.
All reactions