473,387 Members | 3,684 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,387 software developers and data experts.

C++ get time in milliseconds

Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.
i hope i will get the help
thanks & regards
Saurabh

Jun 2 '06 #1
7 99788

Saurabh wrote:
Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.
i hope i will get the help
thanks & regards
Saurabh


gettimeofday()

Jun 2 '06 #2

Saurabh wrote:
Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.
i hope i will get the help
thanks & regards
Saurabh


Hi,

You can use clock_t from standard library to measure short intervalls
of time. from a millisec to some seconds. You can convert it to seconds
with CLOCKS_PER_SEC macro.
example:
#include<ctime>
#include<time.h> // I don't know which1 exactly :)
clock_t t1=clock();
for(int i=0; i<1000000;i++);
clock_t t2=clock();
cout<<"Iterations took for" << doubel(t2-t1)/CLOCK_PER_SEC << "seconds";

Jun 2 '06 #3
wallaby.curious.about...@gmail.com wrote:
Saurabh wrote:
Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.
i hope i will get the help
thanks & regards
Saurabh


Hi,

You can use clock_t from standard library to measure short intervalls
of time. from a millisec to some seconds. You can convert it to seconds
with CLOCKS_PER_SEC macro.
example:
#include<ctime>
#include<time.h> // I don't know which1 exactly :)
clock_t t1=clock();
for(int i=0; i<1000000;i++);
clock_t t2=clock();
cout<<"Iterations took for" << doubel(t2-t1)/CLOCK_PER_SEC << "seconds";


clock() measures processor time however.

Jun 2 '06 #4
ftime

Saurabh wrote:
Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.
i hope i will get the help
thanks & regards
Saurabh


Jun 4 '06 #5
Saurabh wrote:
Hi ,

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.


You did? Searching for "time millisecond" in comp.lang.c++ gives some
pretty good results.

Time and date features are found in <ctime>. However, what the accuracy
of time() is implementation defined. Implementations are not even
required to provide a working time() function.

That <ctime> "provides accuracy up to seconds" is wrong, I think. POSIX
requires CLOCKS_PER_SEC to be 1,000,000 (microseconds) and Windows has
1000 (millisecond, on Visual C++ 2005).

You may be better served by platform specific features if you require
more precise timing. See
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9 for
newsgroup suggestions.
Jonathan

Jun 4 '06 #6
"Jonathan Mcdougall" writes:
Saurabh wrote:

i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.


You did? Searching for "time millisecond" in comp.lang.c++ gives some
pretty good results.


Google and Google groups are two entirely different worlds. Which I, and I
suspect a lot of seasoned users, forget from time to time.
Jun 4 '06 #7
osmium wrote:
"Jonathan Mcdougall" writes:
Saurabh wrote:
i am working with g++ on Linux.is there a way in C++ to get current
time in milliseconds.( <ctime> provides accuracy upto seconds).
I googled for it,searched the newsgroup but couldnt find anything.


You did? Searching for "time millisecond" in comp.lang.c++ gives some
pretty good results.


Google and Google groups are two entirely different worlds.


They index different things but they are "search engines", as far as I
know. Search thoroughly or don't search at all.

I rarely suggest posters to STFW, but I do rant a bit when I see "I did
searched for it, but couldn't find anything".
Which I, and I
suspect a lot of seasoned users, forget from time to time.


Does that apply to me? The OP specifically said "I googled for it,
searched the newsgroup but couldn't find anything".
Jonathan

Jun 5 '06 #8

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

Similar topics

6
by: Richard Visser | last post by:
Hi, i've found this DateRangeSelector : http://www.petrafex.com/view/pgID/21/db/pages/date_range_selector_date_manip ulation__dates_.html . This works fine but i need it to send the dates as :...
2
by: Kevin Thomas | last post by:
Hello, I have a date value in a table SQL Server database that looks like this: 2005-10-11 12:54:36.860 When I load the record into a dataset in VB.NET and retrieve the date value into code,...
11
by: S_at_work | last post by:
hello, can anybody give me a piece of code , or a hint , how i can recieve the time i need for connect() to another host in milliseconds. My problem is i want test the performance of...
26
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
2
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the...
3
by: rdudejr | last post by:
Hi all, Ive got a database approx 350 GB in which Im getting very high Time waited for prefetch. This is directly out of the snapshot for the db (these are for the entire database I assume as I...
3
by: buntyindia | last post by:
Hi, I have a time related issue. Our application servers are hosted in US Central. So when cookie created by the application it contains US Central Time with DST. When we use it in India time...
1
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming...
16
by: neelsfer | last post by:
I need to add milliseconds to this finishtime of race !!! = Format(Now(), "General Date") Start code for race also in milliseconds !!! = Format(Now(), "General Date") I will then subtract it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.