mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 23:46:00 -06:00
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:
parent
b220c2762f
commit
f89cd51416
@ -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";
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuSummaryQuantityNameInfoProvider* RiuSummaryQuantityNameInfoProvider::instance()
|
||||
{
|
||||
static RiuSummaryQuantityNameInfoProvider* singleton = new RiuSummaryQuantityNameInfoProvider;
|
||||
static auto* singleton = new RiuSummaryQuantityNameInfoProvider;
|
||||
return singleton;
|
||||
}
|
||||
|
||||
@ -52,7 +52,8 @@ RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else if ( quantity.size() > 1 && quantity[1] == 'U' )
|
||||
|
||||
if ( quantity.size() > 1 && quantity[1] == 'U' )
|
||||
{
|
||||
// User defined vector name
|
||||
// The summary type is given by the first letter, and U defines user-defined
|
||||
@ -62,7 +63,7 @@ RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo
|
||||
|
||||
return RiuSummaryQuantityInfo();
|
||||
}
|
||||
else if ( quantity.size() > 5 )
|
||||
if ( quantity.size() > 5 )
|
||||
{
|
||||
// Check for custom vector naming
|
||||
|
||||
@ -112,12 +113,12 @@ RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityNameInfoProvider()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo>
|
||||
std::unordered_map<std::string, RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo>
|
||||
RiuSummaryQuantityNameInfoProvider::createInfoForEclipseKeywords()
|
||||
{
|
||||
using A = RifEclipseSummaryAddress;
|
||||
|
||||
std::map<std::string, RiuSummaryQuantityInfo> info;
|
||||
std::unordered_map<std::string, RiuSummaryQuantityInfo> info;
|
||||
|
||||
info.insert( { "FOPR", { A::SUMMARY_FIELD, "Oil Production Rate" } } );
|
||||
info.insert( { "FOPRA", { A::SUMMARY_FIELD, "Oil Production Rate above GOC" } } );
|
||||
@ -2149,18 +2150,18 @@ std::map<std::string, RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo>
|
||||
std::unordered_map<std::string, RiuSummaryQuantityNameInfoProvider::RiuSummaryQuantityInfo>
|
||||
RiuSummaryQuantityNameInfoProvider::createInfoFor6xKeywords()
|
||||
{
|
||||
using A = RifEclipseSummaryAddress;
|
||||
|
||||
std::map<std::string, RiuSummaryQuantityInfo> info;
|
||||
std::unordered_map<std::string, RiuSummaryQuantityInfo> info;
|
||||
|
||||
int nporo = 6;
|
||||
for ( int iporo = 0; iporo < nporo; ++iporo )
|
||||
{
|
||||
std::string suffix( "" );
|
||||
std::string descadd( "" );
|
||||
std::string suffix;
|
||||
std::string descadd;
|
||||
if ( iporo == 1 )
|
||||
{
|
||||
suffix = "F";
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -57,9 +57,9 @@ private:
|
||||
|
||||
RiuSummaryQuantityInfo quantityInfo( const std::string& quantity ) const;
|
||||
|
||||
static std::map<std::string, RiuSummaryQuantityInfo> createInfoForEclipseKeywords();
|
||||
static std::map<std::string, RiuSummaryQuantityInfo> createInfoFor6xKeywords();
|
||||
static std::unordered_map<std::string, RiuSummaryQuantityInfo> createInfoForEclipseKeywords();
|
||||
static std::unordered_map<std::string, RiuSummaryQuantityInfo> createInfoFor6xKeywords();
|
||||
|
||||
private:
|
||||
std::map<std::string, RiuSummaryQuantityInfo> m_summaryToDescMap;
|
||||
std::unordered_map<std::string, RiuSummaryQuantityInfo> m_summaryToDescMap;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user