473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Getting system time with high precision

Hi all,
Is there any way of getting the system time, right down to the microsecond,
or even millisecond?

I need to do something a little like this:

int start_time=getTheTimeSomehow(); // Get the current time
doSomethingElse(); // Go and do something
else.
int end_time=getTheTimeSomehow() // What's the time now?
int elapsed_time=end_time-start_time; // How long did it take?

And I need to know the time as accurately as possible.
I would expect there to be a function somewhere, but I just don't know
where.
Mar 26 '07 #1
7 9165
On Mar 26, 10:18 am, "Leigh Sharpe" <lsha...@pacificwireless.com.au>
wrote:
Hi all,
Is there any way of getting the system time, right down to the microsecond,
or even millisecond?

I need to do something a little like this:

int start_time=getTheTimeSomehow(); // Get the current time
doSomethingElse(); // Go and do something
else.
int end_time=getTheTimeSomehow() // What's the time now?
int elapsed_time=end_time-start_time; // How long did it take?

And I need to know the time as accurately as possible.

I would expect there to be a function somewhere, but I just don't know
where.
Check the following link for sample snippet if you using Visual C++

http://msdn.microsoft.com/library/de..._.wcsftime.asp

Mar 26 '07 #2
Leigh Sharpe wrote:
Hi all,
Is there any way of getting the system time, right down to the microsecond,
or even millisecond?
Very likely, but not in a portable way, try an operating system specific
group.

--
Ian Collins.
Mar 26 '07 #3
"Leigh Sharpe" <ls*****@pacificwireless.com.auwrites:
Is there any way of getting the system time, right down to the microsecond,
or even millisecond?
Not in standard C++. There may be OS-specific functions that provide that
capability for your OS, but those wouldn't be on-topic for this group. I'd
suggest asking in a group that's focused on the capabilities of the OS you're
writing for.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Mar 26 '07 #4
"Sherm Pendley" <sp******@dot-app.orgwrote in message
news:m2************@local.wv-www.com...
I'd
suggest asking in a group that's focused on the capabilities of the OS
you're
writing for.

OK. That's the second response along those lines. Which prompts the
question, which group would that be? My target platform is Linux.

Mar 26 '07 #5
Leigh Sharpe wrote:
>
OK. That's the second response along those lines. Which prompts the
question, which group would that be? My target platform is Linux.
You might want to check the FAQ. They ahve a suggested list.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Mar 26 '07 #6
On windows I would use:
QueryPerformanceCounter located in <windows.h>

On Linux I would use:
::gettimeofday located in <sys/time.h>

example Linux Use:

#include <sys/time.h>

const long long TICKS_PER_SECOND = 1000000L;

struct timeval tv;
struct timezone tz;
::gettimeofday(&tv, &tz);
long long quadPart = tv.tv_sec * TICKS_PER_SECOND + tv.tv_usec;

Hope that helps,
Liam
Mar 26 '07 #7
Leigh Sharpe wrote:
"Sherm Pendley" <sp******@dot-app.orgwrote in message
news:m2************@local.wv-www.com...
>I'd
suggest asking in a group that's focused on the capabilities of the OS
you're
>writing for.


OK. That's the second response along those lines. Which prompts the
question, which group would that be? My target platform is Linux.
Try one of these:

comp.os.linux.development.system
comp.os.linux.development.apps
Mar 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RAYYILDIZ | last post by:
Hi; I have some problem. In win32 platform, how I can get system time in location format. Location format is date and time where you are in. In some area's date format is mm.dd.yyyy, dd.mm.yyyy,...
15
by: Donkey | last post by:
Hi, The precision of built-in date type of C is very low. Even using long double float type or double float type, we can only use 12 or 16 digits after the decimal point. What can we do if we want...
7
by: GCRhoads | last post by:
I'm looking for a very basic high-precision arithmetic library. I need to be able to specify a fixed number of bits or decimal digits (32 decimal digits should be all I need). The only arithmetic...
9
by: Neil | last post by:
I'm using an Access MDB as a front end to a SQL 7 database. When I place the system time in a field in Access, it used the user's clock. I'd like to use the SQL Server system time, so that the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.