/************************************************************************* * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #include "TBenchmark.h" #include "TROOT.h" #include "TStopwatch.h" TBenchmark *gBenchmark = 0; ClassImp(TBenchmark) ////////////////////////////////////////////////////////////////////////// // // // TBenchmark // // // // This class is a ROOT utility to help benchmarking applications // // // ////////////////////////////////////////////////////////////////////////// //______________________________________________________________________________ TBenchmark::TBenchmark(): TNamed() { // Benchmark default constructor fNbench = 0; fNmax = 20; fNames = 0; fRealTime = 0; fCpuTime = 0; fTimer = 0; } //______________________________________________________________________________ TBenchmark::TBenchmark(const TBenchmark& bm) : TNamed(bm), fNbench(bm.fNbench), fNmax(bm.fNmax), fNames(0), fRealTime(0), fCpuTime(0), fTimer(0) { // Copy constructor. fNames = new TString[fNmax]; fRealTime = new Float_t[fNmax]; fCpuTime = new Float_t[fNmax]; fTimer = new TStopwatch[fNmax]; for(Int_t i = 0; i= 0) return fCpuTime[bench]; else return 0; } //______________________________________________________________________________ Float_t TBenchmark::GetRealTime(const char *name) { // Returns Realtime used by Benchmark name. Int_t bench = GetBench(name); if (bench >= 0) return fRealTime[bench]; else return 0; } //______________________________________________________________________________ void TBenchmark::Print(const char *name) const { // Prints parameters of Benchmark name. Int_t bench = GetBench(name); if (bench < 0) return; Printf("%-10s: Real Time = %6.2f seconds Cpu Time = %6.2f seconds",name,fRealTime[bench],fCpuTime[bench]); } //______________________________________________________________________________ void TBenchmark::Reset() { // Reset all Benchmarks fNbench = 0; } //______________________________________________________________________________ void TBenchmark::Show(const char *name) { // Stops Benchmark name and Prints results Stop(name); Print((char*)name); } //______________________________________________________________________________ void TBenchmark::Start(const char *name) { // Starts Benchmark with the specified name. // // An independent timer (see class TStopwatch) is started. // The name of the benchmark is entered into the list of benchmarks. // Benchmark can be stopped via TBenchmark::Stop(). // Results can be printed via TBenchmark::Print(). // TBenchmark::Show() can be used to stop benchmark and print results. // If name is an already existing benchmark, timing will resume. // A summary of all benchmarks can be seen via TBenchmark::Summary(). if (!fNames) { fNames = new TString[fNmax]; fRealTime = new Float_t[fNmax]; fCpuTime = new Float_t[fNmax]; fTimer = new TStopwatch[fNmax]; } Int_t bench = GetBench(name); if (bench < 0 && fNbench < fNmax ) { // define a new benchmark to Start fNames[fNbench] = name; bench = fNbench; fNbench++; fTimer[bench].Reset(); fTimer[bench].Start(); fRealTime[bench] = 0; fCpuTime[bench] = 0; } else if (bench >= 0) { // Resume the existing benchmark fTimer[bench].Continue(); } else Warning("Start","too many benchemarks"); } //______________________________________________________________________________ void TBenchmark::Stop(const char *name) { // Terminates Benchmark with specified name. Int_t bench = GetBench(name); if (bench < 0) return; fTimer[bench].Stop(); fRealTime[bench] = fTimer[bench].RealTime(); fCpuTime[bench] = fTimer[bench].CpuTime(); } //______________________________________________________________________________ void TBenchmark::Summary(Float_t &rt, Float_t &cp) { // Prints a summary of all benchmarks. rt = 0; cp = 0; for (Int_t i=0;i