Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle optimizations in code

I am currently writing various optimizations for some code. Each of theses optimizations has a big impact on the code efficiency (hopefully) but also on the source code. However I want to keep the possibility to enable and disable any of them for benchmarking purpose.

I traditionally use the #ifdef OPTIM_X_ENABLE/#else/#endif method, but the code quickly become too hard to maintain.

One can also create SCM branches for each optimizations. It's much better for code readability until you want to enable or disable more than a single optimization.

Is there any other and hopefully better way work with optimizations ?

EDIT : Some optimizations cannot work simultaneously. I may need to disable an old optimization to bench a new one and see which one I should keep.

like image 270
Ben Avatar asked Dec 12 '22 18:12

Ben


1 Answers

I would create a branch for an optimization, benchmark it until you know it has a significant improvement, and then simply merge it back to trunk. I wouldn't bother with the #ifdefs once it's back on trunk; why would you need to disable it once you know it's good? You always have the repository history if you want to be able to rollback a particular change.

like image 113
Oliver Charlesworth Avatar answered Dec 30 '22 11:12

Oliver Charlesworth