]> https://gitweb.dealii.org/ - dealii.git/commitdiff
use range-based loops
authorDenis Davydov <davydden@gmail.com>
Tue, 12 Jun 2018 20:52:03 +0000 (22:52 +0200)
committerDenis Davydov <davydden@gmail.com>
Tue, 12 Jun 2018 20:52:03 +0000 (22:52 +0200)
source/base/timer.cc

index 2aeb758427f0521c502e45f32f37eee131d8cd70..4405aa514189b951349be101f27f744472b2c82e 100644 (file)
@@ -548,10 +548,8 @@ TimerOutput::print_summary() const
 
   // get the maximum width among all sections
   unsigned int max_width = 0;
-  for (std::map<std::string, Section>::const_iterator i = sections.begin();
-       i != sections.end();
-       ++i)
-    max_width = std::max(max_width, (unsigned int)i->first.length());
+  for (const auto &i : sections)
+    max_width = std::max(max_width, (unsigned int)i.first.length());
 
   // 32 is the default width until | character
   max_width                     = std::max(max_width + 1, (unsigned int)32);
@@ -570,11 +568,8 @@ TimerOutput::print_summary() const
           // time. otherwise, we might have generated a lot of overhead in this
           // function.
           double check_time = 0.;
-          for (std::map<std::string, Section>::const_iterator i =
-                 sections.begin();
-               i != sections.end();
-               ++i)
-            check_time += i->second.total_cpu_time;
+          for (const auto &i : sections)
+            check_time += i.second.total_cpu_time;
 
           const double time_gap = check_time - total_cpu_time;
           if (time_gap > 0.0)
@@ -601,12 +596,9 @@ TimerOutput::print_summary() const
           out_stream << "+---------------------------------" << extra_dash
                      << "+-----------+------------"
                      << "+------------+";
-          for (std::map<std::string, Section>::const_iterator i =
-                 sections.begin();
-               i != sections.end();
-               ++i)
+          for (const auto &i : sections)
             {
-              std::string name_out = i->first;
+              std::string name_out = i.first;
 
               // resize the array so that it is always of the same size
               unsigned int pos_non_space = name_out.find_first_not_of(' ');
@@ -616,10 +608,10 @@ TimerOutput::print_summary() const
               out_stream << "| " << name_out;
               out_stream << "| ";
               out_stream << std::setw(9);
-              out_stream << i->second.n_calls << " |";
+              out_stream << i.second.n_calls << " |";
               out_stream << std::setw(10);
               out_stream << std::setprecision(3);
-              out_stream << i->second.total_cpu_time << "s |";
+              out_stream << i.second.total_cpu_time << "s |";
               out_stream << std::setw(10);
               if (total_cpu_time != 0)
                 {
@@ -627,7 +619,7 @@ TimerOutput::print_summary() const
                   // printing silly things such as "2.45e-6%". otherwise print
                   // the actual percentage
                   const double fraction =
-                    i->second.total_cpu_time / total_cpu_time;
+                    i.second.total_cpu_time / total_cpu_time;
                   if (fraction > 0.001)
                     {
                       out_stream << std::setprecision(2);
@@ -681,12 +673,9 @@ TimerOutput::print_summary() const
           out_stream << "+---------------------------------" << extra_dash
                      << "+-----------+------------"
                      << "+------------+";
-          for (std::map<std::string, Section>::const_iterator i =
-                 sections.begin();
-               i != sections.end();
-               ++i)
+          for (const auto &i : sections)
             {
-              std::string name_out = i->first;
+              std::string name_out = i.first;
 
               // resize the array so that it is always of the same size
               unsigned int pos_non_space = name_out.find_first_not_of(' ');
@@ -696,10 +685,10 @@ TimerOutput::print_summary() const
               out_stream << "| " << name_out;
               out_stream << "| ";
               out_stream << std::setw(9);
-              out_stream << i->second.n_calls << " |";
+              out_stream << i.second.n_calls << " |";
               out_stream << std::setw(10);
               out_stream << std::setprecision(3);
-              out_stream << i->second.total_wall_time << "s |";
+              out_stream << i.second.total_wall_time << "s |";
               out_stream << std::setw(10);
 
               if (total_wall_time != 0)
@@ -708,7 +697,7 @@ TimerOutput::print_summary() const
                   // printing silly things such as "2.45e-6%". otherwise print
                   // the actual percentage
                   const double fraction =
-                    i->second.total_wall_time / total_wall_time;
+                    i.second.total_wall_time / total_wall_time;
                   if (fraction > 0.001)
                     {
                       out_stream << std::setprecision(2);
@@ -740,10 +729,8 @@ TimerOutput::print_summary() const
       // otherwise, we might have generated a lot of overhead in this function.
       double check_time = 0.;
 
-      for (std::map<std::string, Section>::const_iterator i = sections.begin();
-           i != sections.end();
-           ++i)
-        check_time += i->second.total_cpu_time;
+      for (const auto &i : sections)
+        check_time += i.second.total_cpu_time;
 
       const double time_gap = check_time - total_cpu_time;
       if (time_gap > 0.0)
@@ -773,11 +760,9 @@ TimerOutput::print_summary() const
                  << "------------+------------+"
                  << "------------+------------+" << std::endl;
 
-      for (std::map<std::string, Section>::const_iterator i = sections.begin();
-           i != sections.end();
-           ++i)
+      for (const auto &i : sections)
         {
-          std::string name_out = i->first;
+          std::string name_out = i.first;
 
           // resize the array so that it is always of the same size
           unsigned int pos_non_space = name_out.find_first_not_of(' ');
@@ -786,13 +771,13 @@ TimerOutput::print_summary() const
           out_stream << "| " << name_out << "| ";
 
           out_stream << std::setw(9);
-          out_stream << i->second.n_calls << " |";
+          out_stream << i.second.n_calls << " |";
 
           if (output_type != wall_times)
             {
               out_stream << std::setw(10);
               out_stream << std::setprecision(3);
-              out_stream << i->second.total_cpu_time << "s |";
+              out_stream << i.second.total_cpu_time << "s |";
               out_stream << std::setw(10);
               if (total_cpu_time != 0)
                 {
@@ -800,7 +785,7 @@ TimerOutput::print_summary() const
                   // printing silly things such as "2.45e-6%". otherwise print
                   // the actual percentage
                   const double fraction =
-                    i->second.total_cpu_time / total_cpu_time;
+                    i.second.total_cpu_time / total_cpu_time;
                   if (fraction > 0.001)
                     {
                       out_stream << std::setprecision(2);
@@ -819,7 +804,7 @@ TimerOutput::print_summary() const
             {
               out_stream << std::setw(10);
               out_stream << std::setprecision(3);
-              out_stream << i->second.total_wall_time << "s |";
+              out_stream << i.second.total_wall_time << "s |";
               out_stream << std::setw(10);
 
               if (total_wall_time != 0)
@@ -828,7 +813,7 @@ TimerOutput::print_summary() const
                   // printing silly things such as "2.45e-6%". otherwise print
                   // the actual percentage
                   const double fraction =
-                    i->second.total_wall_time / total_wall_time;
+                    i.second.total_wall_time / total_wall_time;
                   if (fraction > 0.001)
                     {
                       out_stream << std::setprecision(2);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.