Declare and implement a class for test code execution time - mouthful grass

xiaoxiao2021-03-06  95

//

// File name: TestClk.h

// Author: Fang mouth Amakusa

// Repair date: 2002.9.18

// Write the purpose: declare and implement a class for test code execution time

//

#ifndef testclk_h

#define testclk_h

#include

Const Int Clock_sec = 1000;

Class testCLK

{

Double TimeStart; // Defining Program Start Time

Double TimeEnd; // Define the program end time

Double Protime; // Perform time

PUBLIC:

TestClk ();

Double ProcessStart (); // Process starts

Double Processend (); // Process end timing

Double showtime (); // Display process execution time

~ TestClk ();

}

// The following code is the implementation of the member function

TestClk :: testclk ()

{

TimeStart = 0.0;

TIMEEND = 0.0;

Protime = 0.0;

}

Double testclk :: processstart ()

{

Cout << "Start Timing:" << ENDL;

TimeStart = (double) clock () / (double)

Clock_sec;

Return TimeStart;

}

Double testclk :: processend ()

{

Cout << "end:" << Endl;

TimeEnd = (double) clock () / (double)

Clock_sec;

Protime = TIMEEND-TIMESTART;

Return Protime;

}

Double TestClk :: ShowTime ()

{

Cout << "The execution time is:" << Protime << Endl;

}

TestClk :: ~ TestClk ()

{

Cout << "test end :-D" << endl;

}

#ENDIF

Test code:

#include

#include

#include

#include

#include "testclk.h"

Int main (int Argc, char * argv [])

{

TestClk Testob;

Testob.ProcessStart ();

Cout << "The program is being executed ..." << Endl;

SLEEP (2000);

Cout << "The program is completed !!" << endl;

Testob.Processend ();

Testob.showtime ();

System ("pause");

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-123008.html

New Post(0)