Here is a more concrete example of what I am trying to profile:
There appear to be two main ways I can find to detect threat to a city. One is to check the plot owner and city every time a unit moves in UnitSetXY which will get called dozens of times per turn. The vast majority of calls will be negatives (no threat). So it's what I call programming for the exception. Overhead (slight if done right but still overhead) added to every turn.
The second way involves walking the plots of a city to check for nearby threatsin PlayerDoTurn. It's also programming for the exception (sigh) and it's not perfect but I plan to extend the DLL to add an iterator (along with a bunch of other missing iterators) for city plots, that would make it more effective.
Both add a lot more overhead than I'd like, but such is life. Neither is perfect either, and I end up having to code for edge cases (like city radius is smaller than city's attack range).
I'm in general a bit frustrated with how hard it is to detect threat to a city.