Performance : Use unordered_map

Use of unordered_map gives performance gain of 50% for lookup of addresses based on quantity name. Performance gain due to use of hash inside unordered_map.
This commit is contained in:
Magne Sjaastad
2021-09-12 12:48:28 +02:00
parent b220c2762f
commit f89cd51416
3 changed files with 43 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
#include "gtest/gtest.h"
#include "RiuSummaryQuantityNameInfoProvider.h"
#include <chrono>
//--------------------------------------------------------------------------------------------------
///
@@ -87,3 +88,31 @@ TEST( RiuSummaryQuantityNameInfoProvider, Test6x )
EXPECT_TRUE( cat == RifEclipseSummaryAddress::SUMMARY_WELL );
}
}
TEST( DISABLED_RiuSummaryQuantityNameInfoProvider, PerformanceLookup )
{
std::vector<std::string> values;
values.emplace_back( "WOPT" );
values.emplace_back( "WOPR" );
values.emplace_back( "FOPT" );
values.emplace_back( "FOPR" );
values.emplace_back( "BHP" );
values.emplace_back( "nothing" );
auto start = std::chrono::high_resolution_clock::now();
const size_t iterationCount = 10000000;
for ( size_t i = 0; i < iterationCount; i++ )
{
for ( const auto& s : values )
{
auto category = RiuSummaryQuantityNameInfoProvider::instance()->categoryFromQuantityName( s );
}
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end - start;
std::cout << "RiuSummaryQuantityNameInfoProvider : Duration " << std::setw( 9 ) << diff.count() << " s\n";
}