lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [5397] Fix defect introduced 20050605T0355Z: usec confused


From: Greg Chicares
Subject: [lmi-commits] [5397] Fix defect introduced 20050605T0355Z: usec confused with sec
Date: Sat, 18 Feb 2012 07:06:07 +0000

Revision: 5397
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5397
Author:   chicares
Date:     2012-02-18 07:06:04 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
Fix defect introduced 20050605T0355Z: usec confused with sec

Modified Paths:
--------------
    lmi/trunk/emit_ledger.cpp
    lmi/trunk/group_values.cpp
    lmi/trunk/group_values.hpp
    lmi/trunk/illustrator.cpp
    lmi/trunk/illustrator.hpp
    lmi/trunk/main_cgi.cpp
    lmi/trunk/mec_server.cpp
    lmi/trunk/mec_server.hpp
    lmi/trunk/timer.cpp
    lmi/trunk/timer.hpp
    lmi/trunk/timer_test.cpp
    lmi/trunk/vector_test.cpp

Modified: lmi/trunk/emit_ledger.cpp
===================================================================
--- lmi/trunk/emit_ledger.cpp   2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/emit_ledger.cpp   2012-02-18 07:06:04 UTC (rev 5397)
@@ -117,6 +117,6 @@
         }
 
   done:
-    return timer.stop().elapsed_usec();
+    return timer.stop().elapsed_seconds();
 }
 

Modified: lmi/trunk/group_values.cpp
===================================================================
--- lmi/trunk/group_values.cpp  2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/group_values.cpp  2012-02-18 07:06:04 UTC (rev 5397)
@@ -121,7 +121,7 @@
             IllusVal IV(serial_file_path(file, name, j, "hastur").string());
             IV.run(cells[j]);
             composite.PlusEq(*IV.ledger());
-            result.usec_for_output_ += emit_ledger
+            result.seconds_for_output_ += emit_ledger
                 (serial_file_path(file, name, j, "hastur")
                 ,file
                 ,*IV.ledger()
@@ -136,7 +136,7 @@
         }
     meter->culminate();
 
-    result.usec_for_output_ += emit_ledger
+    result.seconds_for_output_ += emit_ledger
         (serial_file_path(file, "composite", -1, "hastur")
         ,file
         ,composite
@@ -144,9 +144,9 @@
         );
 
   done:
-    double total_usec = timer.stop().elapsed_usec();
-    status() << Timer::elapsed_msec_str(total_usec) << std::flush;
-    result.usec_for_calculations_ = total_usec - result.usec_for_output_;
+    double total_seconds = timer.stop().elapsed_seconds();
+    status() << Timer::elapsed_msec_str(total_seconds) << std::flush;
+    result.seconds_for_calculations_ = total_seconds - 
result.seconds_for_output_;
     return result;
 }
 
@@ -603,7 +603,7 @@
     for(i = cell_values.begin(); i != cell_values.end(); ++i, ++j)
         {
         std::string const name(cells[j]["InsuredName"].str());
-        result.usec_for_output_ += emit_ledger
+        result.seconds_for_output_ += emit_ledger
             (serial_file_path(file, name, j, "hastur")
             ,file
             ,*(*i)->ledger_from_av()
@@ -612,7 +612,7 @@
         }
     }
 
-    result.usec_for_output_ += emit_ledger
+    result.seconds_for_output_ += emit_ledger
         (serial_file_path(file, "composite", -1, "hastur")
         ,file
         ,composite
@@ -620,9 +620,9 @@
         );
 
   done:
-    double total_usec = timer.stop().elapsed_usec();
-    status() << Timer::elapsed_msec_str(total_usec) << std::flush;
-    result.usec_for_calculations_ = total_usec - result.usec_for_output_;
+    double total_seconds = timer.stop().elapsed_seconds();
+    status() << Timer::elapsed_msec_str(total_seconds) << std::flush;
+    result.seconds_for_calculations_ = total_seconds - 
result.seconds_for_output_;
     return result;
 }
 

Modified: lmi/trunk/group_values.hpp
===================================================================
--- lmi/trunk/group_values.hpp  2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/group_values.hpp  2012-02-18 07:06:04 UTC (rev 5397)
@@ -52,14 +52,14 @@
 struct census_run_result
 {
     census_run_result()
-        :completed_normally_    (true)
-        ,usec_for_calculations_ (0.0)
-        ,usec_for_output_       (0.0)
+        :completed_normally_       (true)
+        ,seconds_for_calculations_ (0.0)
+        ,seconds_for_output_       (0.0)
         {}
 
     bool completed_normally_;
-    double usec_for_calculations_;
-    double usec_for_output_;
+    double seconds_for_calculations_;
+    double seconds_for_output_;
 };
 
 /// Run all cells in a census.

Modified: lmi/trunk/illustrator.cpp
===================================================================
--- lmi/trunk/illustrator.cpp   2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/illustrator.cpp   2012-02-18 07:06:04 UTC (rev 5397)
@@ -50,10 +50,10 @@
 #include <string>
 
 illustrator::illustrator(mcenum_emission emission)
-    :emission_              (emission)
-    ,usec_for_input_        (0.0)
-    ,usec_for_calculations_ (0.0)
-    ,usec_for_output_       (0.0)
+    :emission_                 (emission)
+    ,seconds_for_input_        (0.0)
+    ,seconds_for_calculations_ (0.0)
+    ,seconds_for_output_       (0.0)
 {
 }
 
@@ -69,14 +69,14 @@
         Timer timer;
         multiple_cell_document doc(file_path.string());
         assert_consistency(doc.case_parms()[0], doc.cell_parms()[0]);
-        usec_for_input_ = timer.stop().elapsed_usec();
+        seconds_for_input_ = timer.stop().elapsed_seconds();
         return operator()(file_path, doc.cell_parms());
         }
     else if(".ill" == extension)
         {
         Timer timer;
         single_cell_document doc(file_path.string());
-        usec_for_input_ = timer.stop().elapsed_usec();
+        seconds_for_input_ = timer.stop().elapsed_seconds();
         return operator()(file_path, doc.input_data());
         }
     else if(".ini" == extension)
@@ -85,18 +85,18 @@
         Timer timer;
         Input input;
         bool close_when_done = custom_io_0_read(input, file_path.string());
-        usec_for_input_ = timer.stop().elapsed_usec();
+        seconds_for_input_ = timer.stop().elapsed_seconds();
         timer.restart();
         IllusVal z(file_path.string());
         z.run(input);
         principal_ledger_ = z.ledger();
-        usec_for_calculations_ = timer.stop().elapsed_usec();
+        seconds_for_calculations_ = timer.stop().elapsed_seconds();
         fs::path out_file =
             file_path.string() == c.custom_input_filename()
             ? c.custom_output_filename()
             : fs::change_extension(file_path, ".test0")
             ;
-        usec_for_output_ = emit_ledger
+        seconds_for_output_ = emit_ledger
             (out_file
             ,out_file
             ,*z.ledger()
@@ -125,8 +125,8 @@
     IllusVal IV(file_path.string());
     IV.run(z);
     principal_ledger_ = IV.ledger();
-    usec_for_calculations_ = timer.stop().elapsed_usec();
-    usec_for_output_ = emit_ledger
+    seconds_for_calculations_ = timer.stop().elapsed_seconds();
+    seconds_for_output_ = emit_ledger
         (file_path
         ,file_path
         ,*IV.ledger()
@@ -142,8 +142,8 @@
     run_census runner;
     result = runner(file_path, emission_, z);
     principal_ledger_ = runner.composite();
-    usec_for_calculations_ = result.usec_for_calculations_;
-    usec_for_output_       = result.usec_for_output_      ;
+    seconds_for_calculations_ = result.seconds_for_calculations_;
+    seconds_for_output_       = result.seconds_for_output_      ;
     conditionally_show_timings_on_stdout();
     return result.completed_normally_;
 }
@@ -154,11 +154,11 @@
         {
         std::cout
             << "\n    Input:        "
-            << Timer::elapsed_msec_str(usec_for_input_)
+            << Timer::elapsed_msec_str(seconds_for_input_)
             << "\n    Calculations: "
-            << Timer::elapsed_msec_str(usec_for_calculations_)
+            << Timer::elapsed_msec_str(seconds_for_calculations_)
             << "\n    Output:       "
-            << Timer::elapsed_msec_str(usec_for_output_)
+            << Timer::elapsed_msec_str(seconds_for_output_)
             << '\n'
             ;
         }
@@ -175,19 +175,19 @@
     return principal_ledger_;
 }
 
-double illustrator::usec_for_input() const
+double illustrator::seconds_for_input() const
 {
-    return usec_for_input_;
+    return seconds_for_input_;
 }
 
-double illustrator::usec_for_calculations() const
+double illustrator::seconds_for_calculations() const
 {
-    return usec_for_calculations_;
+    return seconds_for_calculations_;
 }
 
-double illustrator::usec_for_output() const
+double illustrator::seconds_for_output() const
 {
-    return usec_for_output_;
+    return seconds_for_output_;
 }
 
 Input const& default_cell()

Modified: lmi/trunk/illustrator.hpp
===================================================================
--- lmi/trunk/illustrator.hpp   2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/illustrator.hpp   2012-02-18 07:06:04 UTC (rev 5397)
@@ -59,16 +59,16 @@
 
     boost::shared_ptr<Ledger const> principal_ledger() const;
 
-    double usec_for_input       () const;
-    double usec_for_calculations() const;
-    double usec_for_output      () const;
+    double seconds_for_input       () const;
+    double seconds_for_calculations() const;
+    double seconds_for_output      () const;
 
   private:
     mcenum_emission emission_;
     boost::shared_ptr<Ledger const> principal_ledger_;
-    double usec_for_input_;
-    double usec_for_calculations_;
-    double usec_for_output_;
+    double seconds_for_input_;
+    double seconds_for_calculations_;
+    double seconds_for_output_;
 };
 
 Input const& LMI_SO default_cell();

Modified: lmi/trunk/main_cgi.cpp
===================================================================
--- lmi/trunk/main_cgi.cpp      2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/main_cgi.cpp      2012-02-18 07:06:04 UTC (rev 5397)
@@ -526,7 +526,7 @@
 
     std::cout
         << "      Input:        "
-        << Timer::elapsed_msec_str(timer.stop().elapsed_usec())
+        << Timer::elapsed_msec_str(timer.stop().elapsed_seconds())
         << "<BR>\n"
         ;
     if("" == census_data)
@@ -557,10 +557,10 @@
     std::cout << "<hr>\n\n";
     std::cout
         << "    Calculations: "
-        << Timer::elapsed_msec_str(run_functor.usec_for_calculations())
+        << Timer::elapsed_msec_str(run_functor.seconds_for_calculations())
         << "<BR>\n"
         << "    Output:       "
-        << Timer::elapsed_msec_str(run_functor.usec_for_output())
+        << Timer::elapsed_msec_str(run_functor.seconds_for_output())
         << "<BR>\n"
         ;
 }
@@ -667,10 +667,10 @@
     std::cout << "<hr>\n\n";
     std::cout
         << "    Calculations: "
-        << Timer::elapsed_msec_str(run_functor.usec_for_calculations())
+        << Timer::elapsed_msec_str(run_functor.seconds_for_calculations())
         << "<BR>\n"
         << "    Output:       "
-        << Timer::elapsed_msec_str(run_functor.usec_for_output())
+        << Timer::elapsed_msec_str(run_functor.seconds_for_output())
         << "<BR>\n"
         ;
 

Modified: lmi/trunk/mec_server.cpp
===================================================================
--- lmi/trunk/mec_server.cpp    2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/mec_server.cpp    2012-02-18 07:06:04 UTC (rev 5397)
@@ -497,10 +497,10 @@
 } // Unnamed namespace.
 
 mec_server::mec_server(mcenum_emission emission)
-    :emission_              (emission)
-    ,usec_for_input_        (0.0)
-    ,usec_for_calculations_ (0.0)
-    ,usec_for_output_       (0.0)
+    :emission_                 (emission)
+    ,seconds_for_input_        (0.0)
+    ,seconds_for_calculations_ (0.0)
+    ,seconds_for_output_       (0.0)
 {
 }
 
@@ -526,7 +526,7 @@
             }
         mec_xml_document doc;
         doc.read(ifs);
-        usec_for_input_ = timer.stop().elapsed_usec();
+        seconds_for_input_ = timer.stop().elapsed_seconds();
         return operator()(file_path, doc.input_data());
         }
     else
@@ -547,13 +547,13 @@
 {
     Timer timer;
     state_ = test_one_days_7702A_transactions(file_path, z);
-    usec_for_calculations_ = timer.stop().elapsed_usec();
+    seconds_for_calculations_ = timer.stop().elapsed_seconds();
     timer.restart();
     if(mce_emit_test_data && emission_)
         {
         state_.save(fs::change_extension(file_path, ".mec.xml"));
         }
-    usec_for_output_       = timer.stop().elapsed_usec();
+    seconds_for_output_       = timer.stop().elapsed_seconds();
     conditionally_show_timings_on_stdout();
     return true;
 }
@@ -564,11 +564,11 @@
         {
         std::cout
             << "\n    Input:        "
-            << Timer::elapsed_msec_str(usec_for_input_)
+            << Timer::elapsed_msec_str(seconds_for_input_)
             << "\n    Calculations: "
-            << Timer::elapsed_msec_str(usec_for_calculations_)
+            << Timer::elapsed_msec_str(seconds_for_calculations_)
             << "\n    Output:       "
-            << Timer::elapsed_msec_str(usec_for_output_)
+            << Timer::elapsed_msec_str(seconds_for_output_)
             << '\n'
             ;
         }
@@ -579,18 +579,18 @@
     return state_;
 }
 
-double mec_server::usec_for_input() const
+double mec_server::seconds_for_input() const
 {
-    return usec_for_input_;
+    return seconds_for_input_;
 }
 
-double mec_server::usec_for_calculations() const
+double mec_server::seconds_for_calculations() const
 {
-    return usec_for_calculations_;
+    return seconds_for_calculations_;
 }
 
-double mec_server::usec_for_output() const
+double mec_server::seconds_for_output() const
 {
-    return usec_for_output_;
+    return seconds_for_output_;
 }
 

Modified: lmi/trunk/mec_server.hpp
===================================================================
--- lmi/trunk/mec_server.hpp    2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/mec_server.hpp    2012-02-18 07:06:04 UTC (rev 5397)
@@ -64,16 +64,16 @@
 
     mec_state state() const;
 
-    double usec_for_input       () const;
-    double usec_for_calculations() const;
-    double usec_for_output      () const;
+    double seconds_for_input       () const;
+    double seconds_for_calculations() const;
+    double seconds_for_output      () const;
 
   private:
     mcenum_emission emission_;
     mec_state state_;
-    double usec_for_input_;
-    double usec_for_calculations_;
-    double usec_for_output_;
+    double seconds_for_input_;
+    double seconds_for_calculations_;
+    double seconds_for_output_;
 };
 
 #endif // mec_server_hpp

Modified: lmi/trunk/timer.cpp
===================================================================
--- lmi/trunk/timer.cpp 2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/timer.cpp 2012-02-18 07:06:04 UTC (rev 5397)
@@ -51,7 +51,11 @@
 #   endif // LMI_MS_HEADER_INCLUDED
 #endif // LMI_MSW
 
-//============================================================================
+/// Create, calibrate, and start a timer.
+///
+/// Postcondition: 0 < frequency_. Throws if a positive frequency_
+/// cannot be determined.
+
 Timer::Timer()
     :elapsed_time_      (0)
     ,is_running_        (false)
@@ -66,12 +70,12 @@
     start();
 }
 
-//============================================================================
 Timer::~Timer()
 {
 }
 
-//============================================================================
+/// Set elapsed time to zero, and restart timer.
+
 Timer& Timer::restart()
 {
     elapsed_time_ = 0;
@@ -79,7 +83,8 @@
     return *this;
 }
 
-//============================================================================
+/// Stop timer and mark elapsed time. Throws if timer was not running.
+
 Timer& Timer::stop()
 {
     if(!is_running_)
@@ -95,37 +100,46 @@
     return *this;
 }
 
-//============================================================================
-std::string Timer::elapsed_msec_str(double z)
+/// Format argument as a string representing integral milliseconds.
+
+std::string Timer::elapsed_msec_str(double seconds)
 {
     std::ostringstream oss;
-    oss << std::fixed << std::setprecision(0) << 1000.0 * z;
+    oss << std::fixed << std::setprecision(0) << 1000.0 * seconds;
     oss << " milliseconds";
     return oss.str();
 }
 
-//============================================================================
+/// Elapsed time as a string representing integral milliseconds.
+
 std::string Timer::elapsed_msec_str() const
 {
-    return elapsed_msec_str(elapsed_usec());
+    return elapsed_msec_str(elapsed_seconds());
 }
 
-//============================================================================
-double Timer::elapsed_usec() const
+/// Elapsed time in seconds.
+///
+/// Preconditions:
+///  - Timer must have been stopped; throws if it is still running.
+///  - frequency_ must be nonzero (guaranteed by ctor), so that
+///    dividing by it is safe.
+///
+/// The static_casts are necessary in case elapsed_t is integral.
+
+double Timer::elapsed_seconds() const
 {
     if(is_running_)
         {
         throw std::logic_error
-            ("Timer::elapsed_usec() called, but timer is still running."
+            ("Timer::elapsed_seconds() called, but timer is still running."
             );
         }
 
-    // The static_casts are necessary in case elapsed_t is integral.
-    // It is impossible for frequency_ to be zero.
     return static_cast<double>(elapsed_time_) / 
static_cast<double>(frequency_);
 }
 
-//============================================================================
+/// Ascertain timer frequency in ticks per second.
+
 elapsed_t Timer::calibrate()
 {
 #if defined LMI_POSIX
@@ -145,7 +159,8 @@
 #endif // Unknown platform.
 }
 
-//============================================================================
+/// Start timer. Throws if it was already running.
+
 void Timer::start()
 {
     if(is_running_)
@@ -159,7 +174,8 @@
     time_when_started_ = inspect();
 }
 
-//============================================================================
+/// Ticks elapsed since timer started.
+
 elapsed_t Timer::inspect() const
 {
 #if defined LMI_POSIX

Modified: lmi/trunk/timer.hpp
===================================================================
--- lmi/trunk/timer.hpp 2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/timer.hpp 2012-02-18 07:06:04 UTC (rev 5397)
@@ -65,13 +65,6 @@
 /// and that latency is a significant concern. This class uses a high-
 /// resolution timer if available; it's a sharp tool that lets you
 /// make your own decision about that rationale.
-///
-/// Class timer design.
-///
-/// ctor postconditions: frequency_ != 0. Throws if a nonzero
-/// frequency_ cannot be determined.
-///
-/// elapsed_msec_str(), elapsed_usec(), stop(), restart(): nomen est omen.
 
 class LMI_SO Timer
     :private lmi::uncopyable<Timer>
@@ -86,9 +79,9 @@
     Timer&      restart();
     Timer&      stop();
 
-    static std::string elapsed_msec_str(double);
+    static std::string elapsed_msec_str(double seconds);
     std::string        elapsed_msec_str() const;
-    double             elapsed_usec() const;
+    double             elapsed_seconds() const;
 
   private:
     elapsed_t   calibrate();
@@ -190,7 +183,7 @@
 
     f_();
     timer.stop();
-    initial_trial_time_ = timer.elapsed_usec();
+    initial_trial_time_ = timer.elapsed_seconds();
     unit_time_ = initial_trial_time_;
     std::ostringstream oss;
     oss
@@ -229,7 +222,7 @@
         f_();
         }
     timer.stop();
-    unit_time_ = timer.elapsed_usec() / j;
+    unit_time_ = timer.elapsed_seconds() / j;
     std::ostringstream oss;
     oss
         << std::scientific << std::setprecision(3)

Modified: lmi/trunk/timer_test.cpp
===================================================================
--- lmi/trunk/timer_test.cpp    2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/timer_test.cpp    2012-02-18 07:06:04 UTC (rev 5397)
@@ -112,7 +112,7 @@
             break;
             }
         }
-    double observed = timer.stop().elapsed_usec();
+    double observed = timer.stop().elapsed_seconds();
     double relative_error = std::fabs(observed - interval) / interval;
 
     BOOST_TEST_RELATION(relative_error,<,2.0*clock_resolution);
@@ -143,9 +143,9 @@
         );
 
     BOOST_TEST_THROW
-        (timer.elapsed_usec()
+        (timer.elapsed_seconds()
         ,std::logic_error
-        ,"Timer::elapsed_usec() called, but timer is still running."
+        ,"Timer::elapsed_seconds() called, but timer is still running."
         );
 }
 

Modified: lmi/trunk/vector_test.cpp
===================================================================
--- lmi/trunk/vector_test.cpp   2012-02-17 18:02:25 UTC (rev 5396)
+++ lmi/trunk/vector_test.cpp   2012-02-18 07:06:04 UTC (rev 5397)
@@ -352,7 +352,7 @@
     demo1();
 
     std::cout
-        << "        Time (usec) for array0 = array1 + array2 by various 
methods"
+        << "        Time (seconds) for array0 = array1 + array2 by various 
methods"
         << '\n'
         << " length          C             et       et/C         va       va/c"
         << '\n'




reply via email to

[Prev in Thread] Current Thread [Next in Thread]