yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

TravelerList::system_region_miles #228

Open yakra opened 2 years ago

yakra commented 2 years ago

This function. This function right here. https://github.com/yakra/DataProcessing/blob/cc9da66106a7581974938040418b845dcedaf4b2/siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp#L162-L167


  1. Change the name. Probably named in the early "translate from Python" days before I had a clear picture of what was going on. There's nothing regional about it. It's the total across all regions.
  2. https://github.com/yakra/DataProcessing/blob/cc9da66106a7581974938040418b845dcedaf4b2/siteupdate/cplusplus/classes/TravelerList/userlog.cpp#L42-L44 This has to look up the HighwaySystem twice. Once to make sure we're good to call the function, and again once the function is called. Instead, just do double t_system_overall = system_region_miles(h);, have the function catch the exception and keep on truckin', returning 0. Nope! 6.8310 -> 7.0672 s on BiggaTomato. Maybe this could be a good improvement for FreeBSD? :grinning: Try it anyway for giggles... Nope. 5% longer.
  3. https://github.com/yakra/DataProcessing/blob/cc9da66106a7581974938040418b845dcedaf4b2/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp#L167-L172 Eliminating the redundancy here is trickier. It's not as simple as calling the function and proceeding if result > 0, because the iterator is reused later. Maybe dereference it & use std::accumulate.
  4. On that note, would std::accumulate magically be faster for item 1 above? Because accumulators LOL.
yakra commented 2 years ago

userlog versions

tag BT
time
commit descr
522 6.8310 e36c5261466c942a9cf8ac52d952ebfc4726a3c8
hrm1a 6.8232 a021901 std::accumulate with overloaded +. Only check membership @ beginning.
No more derefs yet.
hrm0 6.8316 2 redundant conditionals combined into 1. No diffs. 0.3 ms slower? Just noise! :rofl:
Less code + less branches = good!
hrm1b 6.8363 hrm1a + hrm0 lol I want a mulligan on the time!
hrm1c 6.8355 ff2b65f map_sum template. Fewer lines of code than overloaded +
surely lower compile time than numeric. :P
yakra commented 2 years ago

Seems to make things slower, counterintuitively. Might get back to this later. Rather than overload the + operator & #include <numeric> entirely (compilation time?) to use std:accumulate, here's what I came up with:

template <class map>
double map_sum(const map& m)
{   double sum = 0;
    for (auto& kv : m) sum += kv.second;
    return sum;
}

Leaving this here for now while I delete the branch. May come back to this once other options are in place, e.g. the chop3 branch's to_write & format_clinched_mi optimizations.