Skip to content

Commit

Permalink
Optimized getOutputQuantity to avoid string copies
Browse files Browse the repository at this point in the history
This change leads to a 4% speedup on my laptop with the small
benchmark (20 atoms, 4 of which biased)
  • Loading branch information
GiovanniBussi committed Feb 2, 2024
1 parent 2a3717a commit a8c16a0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/ActionWithValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tools/Exception.h"
#include <vector>
#include <memory>
#include <cstring>

namespace PLMD {

Expand Down Expand Up @@ -185,9 +186,13 @@ double ActionWithValue::getOutputQuantity(const unsigned j) const {

inline
double ActionWithValue::getOutputQuantity( const std::string& name ) const {
std::string thename; thename=getLabel() + "." + name;
int offset=getLabel().size();
for(unsigned i=0; i<values.size(); ++i) {
if( values[i]->name==thename ) return values[i]->get();
const std::string & valname=values[i]->name;
if(valname.size()>offset+1 && valname[offset]=='.' ) {
plumed_dbg_assert(Tools::startWith(valname,getLabel()));
if(!std::strcmp(valname.c_str()+offset+1,name.c_str())) return values[i]->get();
}
}
return 0.0;
}
Expand Down

1 comment on commit a8c16a0

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/MAZE_MEMETIC_SAMPLING.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_RANDOM_WALK.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in MiscelaneousPP.md

Please sign in to comment.