Home | History | Annotate | Download | only in timers
      1 //=====================================================
      2 // File   :  STL_perf_analyzer.hh
      3 // Author :  L. Plagne <laurent.plagne (at) edf.fr)>
      4 // Copyright (C) EDF R&D,  mar dc 3 18:59:35 CET 2002
      5 //=====================================================
      6 //
      7 // This program is free software; you can redistribute it and/or
      8 // modify it under the terms of the GNU General Public License
      9 // as published by the Free Software Foundation; either version 2
     10 // of the License, or (at your option) any later version.
     11 //
     12 // This program is distributed in the hope that it will be useful,
     13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 // GNU General Public License for more details.
     16 // You should have received a copy of the GNU General Public License
     17 // along with this program; if not, write to the Free Software
     18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     19 //
     20 #ifndef _STL_PERF_ANALYSER_HH
     21 #define _STL_PERF_ANALYSER_HH
     22 
     23 #include "STL_timer.hh"
     24 #include "bench_parameter.hh"
     25 
     26 template<class ACTION>
     27 class STL_Perf_Analyzer{
     28 public:
     29   STL_Perf_Analyzer(unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos()
     30   {
     31     MESSAGE("STL_Perf_Analyzer Ctor");
     32   };
     33   STL_Perf_Analyzer( const STL_Perf_Analyzer & ){
     34     INFOS("Copy Ctor not implemented");
     35     exit(0);
     36   };
     37   ~STL_Perf_Analyzer( void ){
     38     MESSAGE("STL_Perf_Analyzer Dtor");
     39   };
     40 
     41 
     42   inline double eval_mflops(int size)
     43   {
     44 
     45     ACTION action(size);
     46 
     47     _chronos.start_baseline(_nb_sample);
     48 
     49     do {
     50 
     51       action.initialize();
     52     } while (_chronos.check());
     53 
     54     double baseline_time=_chronos.get_time();
     55 
     56     _chronos.start(_nb_sample);
     57     do {
     58       action.initialize();
     59       action.calculate();
     60     } while (_chronos.check());
     61 
     62     double calculate_time=_chronos.get_time();
     63 
     64     double corrected_time=calculate_time-baseline_time;
     65 
     66     //    cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl;
     67 
     68     return action.nb_op_base()/(corrected_time*1000000.0);
     69     //return action.nb_op_base()/(calculate_time*1000000.0);
     70 
     71   }
     72 private:
     73 
     74   STL_Timer _chronos;
     75   unsigned long long _nb_sample;
     76 
     77 
     78 };
     79 
     80 
     81 
     82 #endif
     83