yakra / DataProcessing

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

Branchless programming #214

Open yakra opened 2 years ago

yakra commented 2 years ago

From the description of this video:

Have you ever written code like this: void f(bool b, long x, long& s) { if (b) s += x; }

My mind instantly goes to { s += b*x }. (Haha yup. And he gets to exactly that at 56:58 in the video.) Not just C++ -- I've done this kinda thing in Python too (though not committed yet) and it did seem to help a bit:

sqlfile.write("('" + r.root + "','" + t.traveler_name + "','" + str(m) + "','" + str(int(m >= r.mileage)) + "')\n")

can lose if siteupdate.py line numbers from d56e5a67555922d06730363ca779c0acdc224dac

+= operator

|=? &=?


yakra commented 2 years ago

https://www.reddit.com/r/programming/comments/mmjrez/branchless_programming_why_if_is_sloowww_and_what/

yakra commented 2 years ago