Solved

[c++] get system time

Posted on 2007-11-26
2
5,764 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

17 Experts available now in Live!

Get 1:1 Help Now