-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Improve FastRNG implementation #2056
Conversation
int main()
{
#if defined(_DEBUG)
std::print(std::cout, "test on debug build\n");
#else
std::print(std::cout, "test on release build\n");
#endif
constexpr int test_rounds = 10;
constexpr int test_count = 10000000;
FastRNG rgn;
std::minstd_rand stdrgn;
double total1 = 0;
double total2 = 0;
rgn.seed(time(NULL));
stdrgn.seed(time(NULL));
for (int k = 0; k < test_rounds; ++k) {
auto start = axmol::highp_clock();
for (int i = 0; i < test_count; ++i) {
total1 += rgn.rangef(0, 1);
}
auto diff = axmol::highp_clock() - start;
std::print(std::cout, "FastRGN cost: {} ms\n", diff / 1000.0);
start = axmol::highp_clock();
for (int i = 0; i < test_count; ++i) {
total2 += stdrgn() / (double)stdrgn.max();
}
diff = axmol::highp_clock() - start;
std::print(std::cout, "minstd_rand cost: {} ms\n", diff / 1000.0);
}
std::print(std::cout, "total1={}, total2={}", total1, total2);
return 0;
} release build, fast rng is faster than std::minstd_rand, good job, merged |
BTW: do we need move class |
thank @smilediver he's the one that wrote and suggested these awesome optimizations |
come to think of it yeah it should be in the ax namespace |
also some functions need to be static too, I'll do PR |
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.
I've also noticed that this never was in ax
namespace. Maybe it should be added?
miss include |
Describe your changes
improved FastRNG struct to have better performance, clearer inclusive and exclusiveness, and more uniform distribution of random numbers generated.
also improved particle system and cpp-tests
Checklist before requesting a review
For each PR
Add Copyright if it missed:
-
"Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."
I have performed a self-review of my code.
Optional:
For core/new feature PR