#include "stdafx.h"
#include <afx.h>
#include <iostream.h>
// +++ class definition
class ElapsedTimer
{
DWORD dwStarted; // type is unsigned long
public:
inline void Start() { dwStarted = GetTickCount(); }
inline DWORD End()
{ return ( GetTickCount() - dwStarted ); }
inline operator DWORD() { return End(); }
ElapsedTimer() { Start(); }
};
// +++ output program +++
void PrintResult(char *cmd, DWORD t)
{
cout << "Executing " << cmd
<< " took " << t
<< " milliseconds" << endl;
}
// +++ test program +++
int main()
{
char *cmd1 = "copy srcfile destfile";
char *cmd2 = "copy destfile srcfile";
// === time copying a file. ===
ElapsedTimer e; // starts timer
system(cmd1);
PrintResult(cmd1, e); // implicit conversion
// === time copying file back again ===
e.Start(); // using function to restart timer
system(cmd2);
PrintResult(cmd2, e.End()); // explicit call
return 0;
}