Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timer and stats for fps calculation #68

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

lancelot2112
Copy link

Added timer and stats for throughput calculation to get an idea of where the bottlenecks are.

@lancelot2112
Copy link
Author

lancelot2112 commented Dec 4, 2021

sim_time

Created some helper classes for timing. not sure on best way to show stats other than console.log. didn't want to hog throughput on that so updates every second. Max times were logged ~2400 organisms with the sim_time + ui_time == 53.8ms if running on a single thread the max fps would be 18.6fps.

Splitting the sim_time and ui_time onto different threads may be a viable short term improvement. Would change the maximum "simulation" fps calculation for 2400 organisms to just sim_time {20.1ms} or 50fps

@MaxRobinsonTheGreat
Copy link
Owner

I'm actually seeing the infinite fps bug #42 in this. Also could you name your variables more descriptively? val and take in particular are confusing to me. What average is being taken with take anyway, average fps? time per tick?

@lancelot2112
Copy link
Author

lancelot2112 commented Dec 4, 2021

I'll have to look a little closer at the infinity, might just be that two calls to the function happened so close together that the timer resolution wasn't big enough to update? I'll look closer.

It's a generic class, can be used anywhere you need a time or frequency of exec It's not specific until you create an instance of it. There are two instances one for the UI timer and one for the Simulation timer.

Usage

sim_timer = new Timer();  //instance 1
ui_timer = new Timer();  //instance 2

   sim_update() {
       //takes internal state of the sim_timer {instance 1} and get delta time since last update call...  does not modify ui_timer
       sim_timer.update();  
       
       //does not change internal state of timer but calculates delta time since last update call and returns.  
       let sim_exec_time = sim_timer.tick();  
   }

the Stats class is also generic. so it could be used to hold an average for anything. Am I misunderstanding you perhaps? So in the code there are two instances. One for the "tick" stats and one for the "update" stats.

@lancelot2112
Copy link
Author

Were you running firefox perchance? Seems firefox does some rounding to the nearest millisecond, will protect for this.

https://stackoverflow.com/questions/6875625/does-javascript-provide-a-high-resolution-timer

… is rounding timers to nearest ms (or worse)
@lancelot2112
Copy link
Author

Changes to Timer class: changed "tick" to "time_since_last_update" and "update" to "update_state".
Changes to Stats class: changed "take" to "add_value"

src/Engine.js Outdated Show resolved Hide resolved
src/Engine.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants