>write c99
>normal looking code
>write "idiomatic c++" (what trannies want you to do)
>slow crap
>write like "c with classes, templates and constexpr"
>blazing fast
Tip Your Landlord Shirt $21.68 |
UFOs Are A Psyop Shirt $21.68 |
Tip Your Landlord Shirt $21.68 |
>genius discoverers streams are slower than printf
Can I subscribe to your blog to get daily insights?
You didn't noticed the loop is not unrolled? std::for_each version is even worse
>crying about loops not being unrolled
What are cache and branch prediction?
>coping this hard while not understanding programming at all yet wanting to have an opinion
Why are you worried about loop unrolling on a routine that needs to call the fricking kernel? The only reason it's not getting unrolled here is because the compiler recognizes that it's a complex enough routine to not be worth it.
>gcc 12.2 -O3
>gcc 7.2 -O2
>gcc 12.2 -O3
nice bait thread
Exactly the same code generated.
ok, and?
Still slow.
>exactly the same code
>j-just ignore the outline view
>C arrays instead of std::array
Is this C++98?
std::array is the most idiotic thing after std::begin() and std::end() and you can't even have arrays with implicit size with std::array. The only reason you might want to use std::array is for passing as argument and returning, which, in fact, this could be easily done by making the C++ only decay array to pointers explicitly by using static_cast, but no, lets create an bullshit class in STL for nothing.
I don't know if it depends on c++ version or what, but you can easily write your own code which generates array of implicit size.
But it seems like a relatively minor thing to get annoyed about. Surely there are use cases for arrays of explicit size... right?
std::array does deduce size in C++17. And you won't have to write a size function like a moron because it's in std.
there is make_array which deduces for you at the very least
I guess flexibility comes at a slight speed cost. The real question is is this actually significant enough to not be worth it?
As things scales up, it will makes difference.
I do not need to even run it. Loops not unrolled, memory not contiguous (not cache efficient), function calls that could be inlined everywhere, its obviously slower than the "C with classes" style, and its not just because cout vs printf. The only doubt that i have is with "C with classes" vs C99, because at least C99 put everything on the same region.
True that for this particular C++ code is not even important, but this demonstrates how things will scale up as you write your code.
The lack of flexibility also scales up similarly. You're missing the point. Much easier to log with streams. If you need to spend more man hours to do it with printf, but save an irrelevant amount of runtime, then it's not worth it.
>it's another printf is faster than cout for small data thread
WE KNOW! YOU'RE USING IOSTREAM WRONG!
>Be OP
>Be a huge dick sucking homosexual
>Be born into a world of countless tools and innovations
>Find one specific tool I dislike/find problems with
>Decide to cry and piss my pants about it instead of just using what I prefer
>slow crap
Did you benchmark it?
>benchmarking (f)printf vs cout
L M A O
Tell me you never wrote C++ without telling me you never wrote C++
>more asm means slower execution
poo tards itt replying to an obvious bait
Wow, it's almost like calling the `<<` operator defined in the standard headers imports more code into your translation unit than calling a function whose implementation is external. Everyone knows streams are slow, you even use `std::endl` here which doesn't make the implementation identical as you'd need `fflush` on the C version.
>nojob morons stir shit day number ?????
Why didn't you check for errors?
Those who put a newline after function return type deserve a special place in hell
any way to improve the rust version? https://godbolt.org/z/zjzGs3vEv
Doesn't Rust support C FFI? Just import printf and fprintf.