By self-optimizing, I mean:- You have N locations in your code, where two different implementations are possible (it could be more than two, but I'm trying to keep this simple).
- The global performance of your code/module depends on the combination of those N locations (and could be platform specific too).
- N much bigger than 1, says 10, so that would be 1024 combinations to try; too much to do it manually....
So what you could do is:
- Create a benchmark that evaluates the performance of your code.
- Create a batch file that will re-compile your code and run the benchmark in a loop, until some stop condition is detected ("stop file" present?)
- Create a file that will contain the set of flag values, together with benchmark results (initially empty).
- Read the file using staticRead() and put the result in "const"s, such that it can be used in "when" (I assume this is possible)
- When the file is empty, assume all flags are false.
- When the file is not empty, read the last line and "binary increment" the bit-vector (presumably represented as an uint16, since you have 10 flags)
- At the end of the benchmark, add a line with the current flags and result.
- When the last combination was tried, create the stop condition ("stop file")
- Start the batch file, and go take a long break (or let it run on someone else's computer)
- Check the result file to find out the best combination of flags.
- Either hard-code this combination, or put it in a separate file per compilation target...
- Done.
I suspect this general idea might have come up here before. Maybe someone has already coded something like this?