Skip to content

Commit

Permalink
ValuePlugTest : Add performance test for hash cache overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Aug 31, 2023
1 parent d9f9f66 commit 1bff413
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/GafferTest/ValuePlugTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,18 @@ def testCacheOverhead( self ) :
with GafferTest.TestRunner.PerformanceScope() :
GafferTest.repeatGetValue( m["product"], 5000000 )

@GafferTest.TestRunner.PerformanceTestMethod()
def testHashCacheOverhead( self ) :

m = GafferTest.MultiplyNode()
m["product"].getValue()

# As for `testCacheOverhead`, but with an additional context variable, so
# that we have to redo the hash before getting the cached value for the
# compute.
with GafferTest.TestRunner.PerformanceScope() :
GafferTest.repeatGetValue( m["product"], 2000000, "unusedContextVariable" )

@GafferTest.TestRunner.PerformanceTestMethod()
def testContentionForOneItem( self ) :
m = GafferTest.MultiplyNode()
Expand Down
16 changes: 16 additions & 0 deletions src/GafferTestModule/ValuePlugTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ void repeatGetValue( const T *plug, int iterations )
}
}

template<typename T>
void repeatGetValueWithVar( const T *plug, int iterations, const IECore::InternedString iterationVar )
{
IECorePython::ScopedGILRelease gilRelease;
Context::EditableScope scope( Context::current() );
for( int i = 0; i < iterations; i++ )
{
scope.set( iterationVar, &i );
plug->getValue();
}
}

// Call getValue() on the given plug many times in parallel.
//
// Evaluating the same value over and over again is obviously not useful,
Expand Down Expand Up @@ -115,6 +127,10 @@ void GafferTestModule::bindValuePlugTest()
def( "repeatGetValue", &repeatGetValue<FloatPlug> );
def( "repeatGetValue", &repeatGetValue<ObjectPlug> );
def( "repeatGetValue", &repeatGetValue<PathMatcherDataPlug> );
def( "repeatGetValue", &repeatGetValueWithVar<IntPlug> );
def( "repeatGetValue", &repeatGetValueWithVar<FloatPlug> );
def( "repeatGetValue", &repeatGetValueWithVar<ObjectPlug> );
def( "repeatGetValue", &repeatGetValueWithVar<PathMatcherDataPlug> );
def( "parallelGetValue", &parallelGetValue<IntPlug> );
def( "parallelGetValue", &parallelGetValue<FloatPlug> );
def( "parallelGetValue", &parallelGetValue<ObjectPlug> );
Expand Down

0 comments on commit 1bff413

Please sign in to comment.