-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Improved FPS calculation #4250
Improved FPS calculation #4250
Conversation
Fixed point calculation for improved accuracy, dithering in debug builds only. Averaging and optional multiplier can be set as compile flags, example for speed testing with long averaging and a 10x multiplier: -D FPS_CALC_AVG=200 -D FPS_MULTIPLIER=10 The calculation resolution is limited (9.7bit fixed point) so values larger than 200 can hit resolution limit and get stuck before reaching the final value. If WLED_DEBUG is defined, dithering is added to the returned value so sub-frame accuracy is possible in post-processingwithout enabling the multiplier.
@DedeHai looks very good for me, thanks. Two questions
|
edit: |
Thanks for your explanations. I think 511 FPS is future-safe for a long time ;-) |
just for reference: I use this to check FPS in my tests https://pypi.org/project/wled2graph/ |
wled00/FX_fcn.cpp
Outdated
#ifdef WLED_DEBUG | ||
return (FPS_MULTIPLIER * (_cumulativeFps + (random16() & 63))) >> 7; // + random("0.5") for dithering | ||
#else | ||
return (FPS_MULTIPLIER * _cumulativeFps) >> 7; // _cumulativeFps is stored in fixed point 9.7 bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace all places with "7" by a constant (#define) ?
Its better for maintainability to leave a hint what the magic number "7" stands for - in this case the fixed point fraction bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
dithering is not really needed, the FPS_MULTIPLIER is a much better option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 I approve
Actually the old FPS code was always "broken" in a sense that it stops converging to real FPS when the delta is below 2. So we could see this as a bugfix that would fit into 0.15.
This improvement is for dev purposes mainly but it also gives a bit smoother FPS return values in normal builds.
Changes:
- dithering (in debug builds only)Example for speed testing with long averaging and a 10x multiplier:
Since the calculation resolution is limited (9.7bit fixed point)
FPS_CALC_AVG
values larger than 200 can hit resolution limit and get stuck before reaching the final value.If
WLED_DEBUG
is defined, dithering is added to the returned value so sub-frame accuracy is possible in post-processing without enabling the multiplier.