diff --git a/src/tools/Stopwatch.cpp b/src/tools/Stopwatch.cpp index 344c719147dddc8b5cdada26bd27435ddf3feafc..67d8f61279a7beab7326480e3caf6d6c479cee38 100644 --- a/src/tools/Stopwatch.cpp +++ b/src/tools/Stopwatch.cpp @@ -25,6 +25,8 @@ #include <cstdio> #include <iostream> +#include <vector> +#include <algorithm> /* Different clocks can be used @@ -147,9 +149,13 @@ std::ostream& Stopwatch::log(std::ostream&os)const{ buffer[0]=0; for(unsigned i=0;i<40;i++) os<<" "; os<<" Cycles Total Average Minumum Maximum\n"; - for(map<string,Watch>::const_iterator it=watches.begin();it!=watches.end();++it){ - const Watch&t((*it).second); - std::string name((*it).first); + + std::vector<std::string> names; + for(const auto & it : watches) names.push_back(it.first); + std::sort(names.begin(),names.end()); + + for(const auto & name : names){ + const Watch&t(watches.find(name)->second); os<<name; for(unsigned i=name.length();i<40;i++) os<<" "; std::sprintf(buffer,"%12u %12.6f %12.6f %12.6f %12.6f\n", t.cycles, double(t.total), double(t.total/t.cycles), double(t.min),double(t.max)); diff --git a/src/tools/Stopwatch.h b/src/tools/Stopwatch.h index 611cc8d1279c47431fb51c95790feff1c0c15ab8..f49047c1a4b6214c6ab014907f121b2f77177ffe 100644 --- a/src/tools/Stopwatch.h +++ b/src/tools/Stopwatch.h @@ -23,7 +23,7 @@ #define __PLUMED_tools_Stopwatch_h #include <string> -#include <map> +#include <unordered_map> #include <iosfwd> namespace PLMD{ @@ -126,7 +126,7 @@ class Stopwatch{ void stop(); void pause(); }; - std::map<std::string,Watch> watches; + std::unordered_map<std::string,Watch> watches; std::ostream& log(std::ostream&)const; public: /// Start timer named "name"