-
Notifications
You must be signed in to change notification settings - Fork 113
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
base: develop
Are you sure you want to change the base?
Conversation
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 |
I'm actually seeing the infinite fps bug #42 in this. Also could you name your variables more descriptively? |
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. |
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)
Changes to Timer class: changed "tick" to "time_since_last_update" and "update" to "update_state". |
Added timer and stats for throughput calculation to get an idea of where the bottlenecks are.