/dpt/ - daily programming thread

Old: What are you working on, /dpt/?

Attached: https___m.media-amazon.com_images_I_51PSPK68GEL._SL500_.jpg (350x448, 19.69K)

Other urls found in this thread:

cppstories.com/2020/10/understanding-invoke.html/
twitter.com/SFWRedditGifs

Making a Slay the Spire headless clone in Rust so I can generate game runs. Hoping to use this to train a StS AI that can play the game.

What the hell is the python convention for using " and ' for strings?
It seems like both do the same?

Just try to be consistent

ohhhh you....

The bottleneck is using par_unseq in the count loop

they are neck and neck in runtime now

and in fact, the new version using resize_and_overwrite is consistently faster than the existing one, though it is barely anything.

Its got some quirks to work out but my lightmapper is working now

Attached: Screenshot (726).png (1589x839, 669.43K)

Where the fuck are my core dumps being saved?

EVERYTHING I WANT TO LEARN I COULD HAVE LEARNED 10 YEARS AGO BUT HERE I AM NOW SPENDING EVERY DAY TRYING TO BE 10% AS GOOD AS PEOPLE WHO STARTED 20 YEARS AGO IM NEVER GOING TO MAKE IT AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

that's not true user, I learned the basics of C++ using the OP pic book like 20 years ago, then did fuck all for 10 years and here I am 30something trying to get a programming job.

You definitely have time.

YOU WILL NEVER MAKE IT EITHER, GETTING A JOB AT 30 ISN'T MAKING IT WE'RE FUCKED AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

Don't worry bros open AI will kill us before the end of the decade, job isn't that important

Final version here, roughly half the time of the original. The difference between calling reserve() and resize() is massive, always do a resize() directly if possible.

/// returns a string with all separator characters removed
[[nodiscard]] static std::string RemoveSeparatorsOld(const std::string_view numberString)
{
static constexpr char SepChar{ ',' };
const auto sepCount = std::count_if(numberString.begin(), numberString.end(), [](const auto elem)
{
return elem == SepChar;
});
if (sepCount > 0)
{
std::string buf;
buf.resize((numberString.size() - sepCount));
std::remove_copy_if(numberString.begin(), numberString.end(),
buf.begin(),
[](const auto elem) { return elem == SepChar; });
return buf;
}
return { numberString.begin(), numberString.end() };
}


It just means the companies that hire us will be much happier with us because we won't want to leave. They will figure that out eventually too, essentially we are a resource they haven't learned they need to use yet. With the entire world in recession will they really tolerate flooding every industry with H1b's? It will be a losing proposition when your electorate needs the income to fucking afford food.

And after all, what exactly were you expecting? Working is just fine user, you get to talk to people and do stuff. Plus you actually make good money. Software jobs are way better in that regard, a lot of the factories want fucking 10 hour days 6-7 days a week. So either quit your bitching and keep looking, or take the factory job (and probably still keep looking kek).

Did you try one without counting the separators? I wonder if it's worth it.

Reminder that no matter how hard you try, you'll never be this good

yes it is absolutely worth it.

the memory allocation is the time consuming part there, literally the loop for counting the sep chars is almost nothing in comparison to asking the OS for more memory lol.

in my test setup with randomly generated character strings, counting the seps first and calling resize() directly with the new size makes it take about half the time compared to just push_back()ing

one odd thing I noticed is that calling resize() instead of reserve() also helped tremendously, perhaps not needing the back_inserter object is what did it.

But resizing and writing directly to the new range is the way to go.

I was thinking you could just overallocate instead of calculating the exact number of bytes you need. You'd still get the benefit of the single resize() but you don't have to go over the input twice. But I think it would depend on what percentage of the input is separators.

hmm I see, perhaps keep a running count for the new size during the remove_copy_if loop?

will give it a try, also trying to figure out how to use the ranges::projection capability, got this queued up to read cppstories.com/2020/10/understanding-invoke.html/

remove_copy_if returns the end iterator for the target range, so you could calculate the new size from that.

about 25% of the input is going to be separator characters, so that may not be a good approach