Design a CPU Timer class (you may name it CPUTimer). This class should allow the user to start timer, stop timer, compute delta time and print the lapsed CPU time of any block of code in a program.

#pragma once
#include <iostream>
#include <cmath>
#include <ctime>
#ifndef CPUTimer_h
#define CPUTimer_h

using namespace std;


class CPUTimer
{
private:
    long t0;
    long t1;


public:
    CPUTimer(void); 
    ~CPUTimer(void);


    void startSetT0();
    long getT0();


    void stopSetT1();
    long getT1();


    void printTimeConsumed ();
};
#endif


int main ()
{
    CPUTimer counter;


    counter.startSetT0();


    for(float i=0; i<10000000; ++i) 
        pow(i,i) * sqrt(i*i) / exp(i);


    counter.stopSetT1();
    counter.getT1();
    counter.printTimeConsumed();


    return 0;
}




CPUTimer::CPUTimer(void)
{
}


CPUTimer::~CPUTimer(void)
{
}

void CPUTimer::startSetT0()
{
    t0=clock();
}

void CPUTimer::stopSetT1()
{
    t1 = clock ();
}

long CPUTimer:: getT0(){
    return t0;
}
long CPUTimer::getT1(){


    return t1-t0;
}




void CPUTimer::printTimeConsumed ()
{ 
    cout << "CPU times in ms below... " << endl << endl;
    cout << "CPU start time in ms ===> " << t0 << endl;
    cout << "CPU stop time in ms ====> " << t1 << endl;
    cout << "CPU running time change in ms ===>The change in CPU running time in ms = " << t1-t0 << endl << endl;
    system("pause");
};
Member Avatar for MonsieurPointer

What exactly do you need help with?

commented: I felt like I was done with the program but I've been told I'm missing a part not sure what though. +0
commented: Proper question +12
Member Avatar for MonsieurPointer

I felt like I was done with the program but I've been told I'm missing a part not sure what though.

If you are not sure, how can I be?

And one more thing: Not knowing what you want then voting down my previous post / question is not looking good on your part.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.