Comments (8)
The only rationale that I used was that a chrono::time_point
is typically the same size as a scalar (more often 64 bit but sometimes 32 bit), and that the compiler would probably pass it by value in a register just as easily.
However I never measured (before now).
I just did an experiment inspecting the optimized assembly of this test:
std::string
test(std::chrono::system_clock::time_point tp)
{
return date::format("%F %T", tp);
}
There were differences, but the differences are likely in the noise level. Some operations were moved from one place to another. Overall, the line count on the assembly listing was 0.29% smaller for the const&
test.
I can't really get excited about one way vs the other. However if you prefer the const&
version and no one else prefers the by-value version, I'll make it const&
.
from date.
Thanks - all things being equal, I do prefer the const local_time&
format for reasons pertaining to the constness of parameters involved in string-output operations.
I can get around with my own overrides/wrappers which take a const &
, make a copy and calls into the target function - 5-10 extra lines of code for the entire project - so, low priority, no hurry and no probs if you close this with WONTFIX.
As I said, it's not a matter of performance/overhead, but rather a matter of lines of code one needs to write to achieve the needed functionality (for some times now it got stuck in my head this weird idea of 'while an executable is an assets, to source code required to get it is a liability'. And I'm afraid I won't be able to get help from any shrink on the matter ;) )
from date.
Ah, on the same line... would you consider++ doubling the number of format functions with ostream& format(ostream& os, ...)
-signature methods? After all, all the format
functions land into
date::detail::format(....) { // heaps of work and then at the end... f.put(os, os, os.fill(), &tm, fmt.data(), fmt.data() + fmt.size()); // -----^-- already an ostream return os.str(); }
++ ;) do they call this "cost externalization"?
Seriously speaking, if you accept the request, it'd be Ok for me to do it and raise a PR.
from date.
I'm not crazy about the idea. But I'll give it some thought.
from date.
The pass by const&
issue is addressed in 86446a9
I'm leaving this open for now as I'm still contemplating your suggestions on format
streaming directly to a ostream
.
from date.
Thanks.
The argument in favour of the second is a matter of performance and performance only - the second form breaks the 'fluency' of the l-shift operator
std::cout << "Date of birth: " << date::format(fmtstr, tp) << std::endl << "Sex: yes, please" << std::endl ;
vs
std::cout << "Date of birth:"; date::format(std::cout,fmtstr, tp); std::cout << std::endl << "Sex: yes, please" << std::endl ;
But I'd choose the second when performance is required and code fluency is not an issue (e.g. remote services with json interfaces)
from date.
The 2nd form also doesn't respect width
and adjustfield
formatters. And even if I create the 2nd form, it will still have to create ostringstream
internally for %z
and for %S
and %T
when the precision is finer than seconds (somewhat nullifying the performance argument).
That being said, your request also induced me to take another look at parse
. I have an experiment running now that accepts this syntax:
std::istringstream infile{"2013-06-13 11:00:45 2013-06-14 09:03:23"};
date::sys_seconds tp1, tp2;
infile >> date::parse("%F %T", tp1) >> date::parse("%F %T", tp2);
which aligns with the current use of format
better.
from date.
Closing for now as the primary issue has been addressed. At this time I don't anticipate creating a format
which takes an ostream
and returns void
. However feel free to open a new issue on this subject if you desire. I have now committed additions to parse
so that it can be used as described per my comment above. This alternative syntax is not significantly different performance wise. It is just an alternative syntax that I like.
from date.
Related Issues (20)
- How to use date/tz.h properly HOT 4
- When I compile on x64 uwp I get the error HOT 1
- Waybar fails to compile with clang/libcxx because of date/tz.h HOT 8
- Change the type of the data member of class year to int from short HOT 3
- Undefined symbol HOT 1
- date_test_pass_parse_test fails with gcc (Debian 10.2.1-6) 10.2.1 20210110 HOT 1
- Date Parse: one pattern for ISO8601 DATE or DATE TIME HOT 6
- How can I convert between std::chrono::time_point and string (2023-12-06 00:46:45.801479+08)? HOT 4
- OSSFuzz Integration HOT 9
- Incorrect value of date::sys_info::save HOT 1
- Cannot override CMake options when fetching the library via FetchContent_Declare()
- .zip files have "text" git attribute HOT 1
- Possibly big performance improvement for `time_zone::to_sys()` HOT 10
- Failed to install tzdb HOT 2
- Transform date::local_seconds and timezone offset to struct tm HOT 1
- Missing tz.h header file when selecting compiler for ARM architecture HOT 1
- Opposite inner 'if' condition leads to a dead code block HOT 1
- Use timezone name like "-08:00" for `locate_zone()` HOT 2
- date::parse() doesn't have a formatting character for ISO 8601 strings without 'T' separator HOT 2
- How to parse datetime with milliseconds and timezone? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from date.