mensahs / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

PATCH : Performance Enhancement for MockHandler : Search matchers once instead of twice #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello - the attached patch is a performance-enhancement for MockHandler,
reducing execution time from 105 seconds to 82 seconds for a particular set
of tests I'm currently working on.

MockHandler currently calls these 2 methods in quick succession when
providing the stubbed result for an invocation:

mockitoStubber.hasResultFor(invocation)
mockitoStubber.getResultFor(invocation)

Unfortunately this involves duplication of work, because both methods call
findMatch(invocation), which in turn will search *all* of the stubbed
invocations against this mock instance. The search is performed twice, when
it only needs to be performed once.

Reasonably, of course, there will usually only be a few stubbed invocations
against the mock object, and the matchers will be simple, so the search
will be fast, and the repetition doesn't matter. Unfortunately, I'm using
Mockito in a way in which it was probably not intended to be used, and so I
have around 8000 stubbed invocations against my mock (these are generated
using a log file produced by a Fortran program I'm attempting to port - see
http://sharesource.org/project/sasa/), and some moderately complicated
matchers, so executing the search twice rather than once becomes a
significant factor on test duration - the netbeans profiler put the cost of
each search at 35% of my test runtime, so I'd be happy to claim that back!

I'm hoping to reduce the insane number of stubbed invocations against my
mocks, but in the meantime this performance enhancement may be useful to
others.

Szczepan, forgive me for abusing your wonderful Mockito!

best regards,

Roberto

Original issue reported on code.google.com by roberto....@gmail.com on 17 Aug 2008 at 11:04

Attachments:

GoogleCodeExporter commented 8 years ago
Incidentally, this issue should be an 'Enhancement' rather than a 'Defect', but 
I
couldn't see anywhere to set that on 
http://code.google.com/p/mockito/issues/entry ...

Original comment by roberto....@gmail.com on 17 Aug 2008 at 11:06

GoogleCodeExporter commented 8 years ago
Changed the type to enhancement

Original comment by iczechowski@gmail.com on 18 Aug 2008 at 2:31

GoogleCodeExporter commented 8 years ago
Committed to trunk. Nice job!

Roberto, I'm hoping it was the last time you abused Mockito! :D

Szczepan

Original comment by szcze...@gmail.com on 23 Aug 2008 at 3:10

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 23 Aug 2008 at 3:10

GoogleCodeExporter commented 8 years ago
just recovering from last night - it was the guardian farewell party for 
thoughtworks
and everyone down at Guanabara in holborn and the drink of the night was -of 
course-
mojitos... which I definitely abused :)

Original comment by roberto....@gmail.com on 23 Aug 2008 at 6:18

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 19 Apr 2009 at 7:40

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 2 Dec 2012 at 10:21