Skip to content
Snippets Groups Projects
Commit 545ddb70 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Replacing map with unordered_map in stopwatch

This should make the code slightly fast.
Notice that it is now necessary to explicitly sort the watches
when printing the log.
parent 64da1287
No related branches found
No related tags found
No related merge requests found
......@@ -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));
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment