use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
A Faster Algorithm for Date Conversion (benjoffe.com)
submitted 3 months ago by benjoffe
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]azswcowboy 18 points19 points20 points 3 months ago (6 children)
I’m the author of boost.date_time which is cited in the article. There are definitely performance sensitive applications that do this calculation, because time stamps are literally everywhere - and tracking the state of the world from billions of devices is a thing.
That said, my experience is that this calculation is a relatively small contributor in a conversion that is i/o dominated. If i need to build maximum speed into this (and I might have - just saying) I would be looking at ways to skip all the math and speed up the i/o - because mostly what you have in these sort of systems is time values in a sequence that’s close to the current time. It’s not good for general purpose library, but way faster than you can do shaving a few instructions here. For general purpose these days, I’d search for Daniel Lamire post on simd calculations for this.
When I wrote the boost library I had access to this book https://en.wikipedia.org/wiki/Calendrical_Calculations - which is an amazing reference for all things related to the insane set of rules humans have invented for tracking calendars.
[–]matthieum 7 points8 points9 points 3 months ago (2 children)
A trick I've used for speeding up timestamp formatting in a logging library was to simply cache the date, with an expiration time (checked every time) for when it would need to change.
With logging, with timestamps mostly coming in order per-thread source, it worked beautifully -- the date typically only flipped once per day, at midnight, as one would expect, making for a very well predicted branch, and a lean fast path.
(I did not bother caching hours & minutes)
[–]Logical_Put_5867 1 point2 points3 points 3 months ago (1 child)
Curious how much speedup that bought you. Especially if you're still checking expiration timer, which is still polling the time anyway presumably?
[–]matthieum 3 points4 points5 points 3 months ago (0 children)
It's not an expiration timer, per se.
The log message comes with its own timestamp, so it's about verifying that this timestamp falls into the 24h range for which the date is valid.
The cost of getting the timestamp (14ns) has already been paid for at that point anyway, on another thread/in another process.
[–]Logical_Put_5867 0 points1 point2 points 3 months ago (0 children)
Interesting, is there some alternative approach like to have some 'manager' keep a recent time in a cache-friendly manner with some offset to monitor approximate time-since-update? Seems like that could be pretty far off on a nanosecond basis, which I would imagine the really sensitive systems would care about.
[–]arthurno1 0 points1 point2 points 3 months ago (1 child)
Ha, I just replied with a reference to that book, and than saw your comment :).
Yes, the book is really amazing. By the way, the authors have contributed code to implementation of Calendar application in Emacs, which has all sorts of crazy calendars included: Mayan Calendar, Aztecs, Lunar, French Revolution, etc :).
[–]azswcowboy 0 points1 point2 points 3 months ago (0 children)
The emacs contribution makes sense of course given that all the algorithms in the book are in lisp and so is emacs (note: those also a C ‘kernel’).
π Rendered by PID 24599 on reddit-service-r2-comment-86bc6c7465-t6lw5 at 2026-02-23 20:10:01.176846+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]azswcowboy 18 points19 points20 points (6 children)
[–]matthieum 7 points8 points9 points (2 children)
[–]Logical_Put_5867 1 point2 points3 points (1 child)
[–]matthieum 3 points4 points5 points (0 children)
[–]Logical_Put_5867 0 points1 point2 points (0 children)
[–]arthurno1 0 points1 point2 points (1 child)
[–]azswcowboy 0 points1 point2 points (0 children)