Main Page | Modules | Namespace List | Data Structures | File List | Data Fields | Globals

Stats.cpp

Go to the documentation of this file.
00001 /*
00002  
00003 Copyright (c) 2004, Cornell University
00004 All rights reserved.
00005  
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008  
00009    - Redistributions of source code must retain the above copyright notice,
00010        this list of conditions and the following disclaimer.
00011    - Redistributions in binary form must reproduce the above copyright
00012        notice, this list of conditions and the following disclaimer in the
00013        documentation and/or other materials provided with the distribution.
00014    - Neither the name of Cornell University nor the names of its
00015        contributors may be used to endorse or promote products derived from
00016        this software without specific prior written permission.
00017  
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00028 THE POSSIBILITY OF SUCH DAMAGE.
00029  
00030 */
00031 
00032 
00033 /////////////////////////////////////////////////////////////////////
00034 /// Stats.cpp
00035 /////////////////////////////////////////////////////////////////////
00036 
00037 #include "Stats.h"
00038 
00039 using namespace std;
00040 
00041 Stats::Stats(int n)
00042 {
00043     numLevels = n;
00044     levelTime = new double[numLevels];
00045     compTime = new double[numLevels];
00046     s_ext = new int[numLevels];
00047     i_ext = new int[numLevels];
00048     numNodes = new int[numLevels];
00049     numComp = new int[numLevels];
00050 
00051     for (int i = 0; i < numLevels; i++)
00052     {
00053         levelTime[i] = 0.0;
00054         compTime[i] = 0.0;
00055         s_ext[i] = 0;
00056         i_ext[i] = 0;
00057         numNodes[i] = 0;
00058         numComp[i] = 0;
00059     }
00060 }
00061 
00062 Stats::~Stats()
00063 {
00064     delete [] levelTime;
00065     delete [] compTime;
00066     delete [] s_ext;
00067     delete [] i_ext;
00068     delete [] numNodes;
00069     delete [] numComp;
00070 }
00071 
00072 void Stats::startLevelTimer()
00073 {
00074     levelStartTime = clock();
00075 }
00076 
00077 void Stats::stopLevelTimer(int level)
00078 {
00079     int levelStopTime = clock();
00080     levelTime[level] += (levelStopTime - levelStartTime) /
00081                         (double)CLOCKS_PER_SEC;
00082 }
00083 
00084 void Stats::startCompTimer()
00085 {
00086     compStartTime = clock();
00087 }
00088 
00089 void Stats::stopCompTimer(int level)
00090 {
00091     int compStopTime = clock();
00092     compTime[level] += (compStopTime - compStartTime) /
00093                        (double)CLOCKS_PER_SEC;
00094 }
00095 
00096 void Stats::updateSExt(int level, int s)
00097 {
00098     s_ext[level] += s;
00099 }
00100 
00101 void Stats::updateIExt(int level, int i)
00102 {
00103     i_ext[level] += i;
00104 }
00105 
00106 void Stats::updateNumNodes(int level, int n)
00107 {
00108     numNodes[level] += n;
00109 }
00110 
00111 void Stats::updateNumComp(int level, int c)
00112 {
00113     numComp[level] += c;
00114 }
00115 
00116 void Stats::printStats(ofstream &output)
00117 {
00118     for (int i = 0; i < numLevels; i++)
00119     {
00120         if (numNodes[i] == 0)
00121         {
00122             break;
00123         }
00124 
00125         output << "Level " << i << endl;
00126         output << "\t Num nodes: " << numNodes[i] << endl;
00127         output << "\t Num comp: " << numComp[i] << endl;
00128         output << "\t Total level time: " << levelTime[i] << endl;
00129         output << "\t Total comp time: " << compTime[i] << endl;
00130         output << "\t Average level time: "
00131         << (levelTime[i] / (double)numNodes[i]) << endl;
00132         output << "\t Average comp time: "
00133         << (compTime[i] / (double)numNodes[i]) << endl;
00134         output << "\t Average s ext: "
00135         << (s_ext[i] / (double)numNodes[i]) << endl;
00136         output << "\t Average i ext: "
00137         << (i_ext[i] / (double)numNodes[i]) << endl << endl;
00138     }
00139 }

Generated on Thu Mar 11 12:01:52 2004 for SPAM by doxygen 1.3.4