hRobert12 / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Performance changes in 0.8 #123

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The performance profile of mock changed a great deal in 0.8. Mock instantiation 
is about twice as slow whereas MagicMock instantiation is much faster. 

The change to using MagicMock by default in patch may cause a slowdown as 
MagicMock is still slower than Mock to instantiate.

repr is dramatically slower but this is unlikely to be a performance bottleneck 
for test suites. repr could be sped up by caching the name after the first time 
it is calculated (refreshing if the mock is re-parented or the spec is changed).

Deeply nested calls are also slower as they are tracked in mock_calls. 
Profiling from any test suites actually slowed down by the move to 0.8 would be 
helpful to know where time is best spent improving performance.

Original issue reported on code.google.com by fuzzyman on 28 Oct 2011 at 11:36

Attachments:

GoogleCodeExporter commented 8 years ago
Note that where patch is used a great deal:

Construction times (instantiating 1000 times)
Mock: old 0.038074016571
MagicMock: new 0.484632015228

MagicMock is about 15 times slower than Mock for instantiation.

Original comment by fuzzyman on 28 Oct 2011 at 11:37

GoogleCodeExporter commented 8 years ago
After some work, instantiating a MagicMock is now only 5 times slower than 
instantiating a Mock *used* to be in 0.7.2. Both Mock and MagicMock 
instantiation could still be improved (why is instantiating a Mock twice as 
slow as it used to be for example).

Original comment by fuzzyman on 29 Oct 2011 at 10:03

GoogleCodeExporter commented 8 years ago
Some more benchmarks:

http://paste.pound-python.org/show/15076/
http://paste.pound-python.org/show/15078/

Much more time is spent in __call__ and also in __setattr__

The move to 0.8 *adds* a lot of calls to __setattr__

Original comment by fuzzyman on 22 Nov 2011 at 12:38

GoogleCodeExporter commented 8 years ago
With current head:

http://paste.pound-python.org/show/15086/

Back down ~10% to around a 60% slowdown.

Original comment by jul...@grayvines.com on 22 Nov 2011 at 7:02

GoogleCodeExporter commented 8 years ago
Closing this issue as I consider mock performance to be "acceptable". If there 
are further performance issues please open a new issue.

Original comment by fuzzyman on 14 Mar 2012 at 6:18