Solved

[c++] get system time

Posted on 2007-11-26
2
5,775 Views
Last Modified: 2008-02-01
I need to benchmark some of my function to see how long it takes for them to run.


is it possible to do this?

time = gettime()


cou << gettime() - time ;
0
Comment
Question by:Troudeloup
  • 2
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20354340
if you want only the difference in seconds, you can use time() function:

time_t t1 = time(NULL);
//do some tasks here
time_t t2 = time(NULL);

cout << "Lapse:" << (t2-t1) << "seconds" << endl;
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20354366
for milliseconds use GetTickCount();

DWORD t1 = GetTickCount();
//do some tasks here
DWORD t2 = GetTickCount();

cout << "Lapse:" << (t2-t1) << "miliseconds" << endl;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now