• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

What are the fastest datetime functions to use in C plus plus

Im designing a program that uses a date loop and a time loop,.  huge iteration overhead that will be eventually clustered out.  My original program has a separate date and then a time loop, time inside date, and Im thinking of integrating both of them them into one loop, The original program used a bespoke algorihm for calculating date and basically a int to keep track of time.  

Heres the question, whats the fastest c++ time structures algorithms etc to use heres a few ive read about to get an answer started:

in time.h
Calendar Time
time_t ?

CTime and CTimeSpan?


I looked around for some new ideas in the visual studio 8 platform, I know C# uses a datetime structure.


Also How the hell do I get a plus sign to appear on this site, as in C plus plus,  I see it now but when the post goes up it disappears so I jhave to use the word plus???

  • 2
  • 2
1 Solution
in my point of view the windows API function is the fastest one as it is optimized by the OS vendor.
and using it can help you bypass the hardware related optimization..

other vendors of hardware like intel are providing there own library but it is optimize for intel platform only.

try to use intel c++ compiler.

hope your problem can be solve.

Each one of the functions/objects you mentioned fulfills some purpose but the fastest are probably the functions defined in the C Standard Library time.h http://www.cplusplus.com/reference/clibrary/ctime/ as they are least abstracted. The various functions you mentioned are part of different implementations i.e. C, C++, Win32 C++, MFC all of which compile to native code and will be faster than any of the C++ .NET, C# code which is compiled to MSIL http://msdn.microsoft.com/en-us/library/c5tkafs1(VS.71).aspx and then processed by the JIT.

The first step would be identify which platform you intend to use to develop your application, i.e. if speed and efficiency are your goal you will probably choose a native code approach preferably as low-level as possible, like C using the methods from time.h, on the other hand if you are interested in ease of development you might go with C++ .NET or C#.

These are just few thoughts I hope will be useful to you. There is a good article about date and time in C++ at http://www.codeproject.com/KB/datetime/datetimedisc.aspx that might be of interest as well.

TheMoogAuthor Commented:
Thats a great post.   Thank you.  Im developing a program for a HPC cluster solution and intent to write it in c/c++ console app as low level as possible.  I then intend to write the GUI written in C# just to operate the dlls and exes, that type of approach.  I want speed and efficiency to be the optimal goal.  Im going to accept your comments as the solution, Im wondering whether you would take a look at another post ill make in a moment on the best memory allocation processes and see if you can make similar comments from that angle.  Thanks again.
TheMoogAuthor Commented:
Thank you very much! I would be happy to take a look at your post and possibly contribute if I can be helpful.

When selecting the Zones for the post you might be interested in selecting the "C++" zone which has more activity and is frequently checked by several excellent experts.

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now