Solved

[c++] get system time

Posted on 2007-11-26
2
5,808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.

688 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