richelbilderbeek / djog_unos_2018

Project by the Uno's at DJOG 2018-2019: Nature Zen
GNU General Public License v3.0
6 stars 2 forks source link

Profiling: reduce use of can_eat #542

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

Is your feature request related to a problem? Please describe.

In recent Travis CI build logs we can observe that 44% of all run-time is spent in can_eat.

Now we can rationally speed up the program, let's reduce the number of times it is called!

What we can see, is that when can_eat is called for any agent, can_eat will always return the same std::vector. We can store that std::vector internally in an agent.

Describe the solution you'd like

Measured Runtime speed
Before 6:02
/// The types of agents this agent can eat
/// Added as a result of profiling
std::vector<agent_type> m_prey;

Do not make a getter for m_prey! It's an implementation detail that should not be exposed.

Measured Runtime speed
Before 6:02
After 2:40

Describe alternatives you've considered

None.

Additional context

None,

richelbilderbeek commented 5 years ago

@robkruger: I assign you this Issue. Feel free to delegate it to others, as long as you take the responsibility to ensure the code is actually sped up!

robkruger commented 5 years ago

The program sped up significantly👍

richelbilderbeek commented 5 years ago

I see here the new speed is 2m12.

Well done!