wesnoth/wesnoth-old — pull request #72 by yieldthought (2013-08-23 19:28:48+00:00)
Title: Speed up AI turns 5-10% by deferring tod creation

Profiling --no-gui runs (I used a commercial tool) showed a surprising
amount of time is spent inside terrain_filter::match_internal. This
appears to mostly be as a result of checking every single terrain tile
to determine where the leader location is, which seems ripe for
optimization itself.

However, within this function 5-10% of the time is spent creating a
time_of_day that is rarely used by these AI matches:

One sample run:
![terrain_filter_run1](https://f.cloud.github.com/assets/946653/1018472/fc8bdcc6-0c29-11e3-98b1-87654d7a46f5.png)

A second sample run (there's a lot of variability as I'm not forcing the PRNG seed here; the AI is playing different matches each time):
![terrain_filter_run2](https://f.cloud.github.com/assets/946653/1018474/0f841000-0c2a-11e3-9120-50b7a1f6cc26.png)

Simply reordering the lines to defer its creation until inside the if
block that checks whether tod is a factor eliminates this part of the
overhead.

This patch speeds AI turns up by 5-10% on my test machine (an 8-core
Linode 2048).