-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
cryptonote_basic: faster and more readable is_valid_decomposed_amount #9122
cryptonote_basic: faster and more readable is_valid_decomposed_amount #9122
Conversation
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.
Left a comment on while
loop.
if (0 == amount) | ||
return false; | ||
|
||
while (amount % 10 == 0) |
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.
Thanks @jeffro256 for this PR. It is great. I have a few comments that we can talk about.
a. It would be great if we could add a small benchmark, and test included in this PR.
b. While a while
loop is simple and easy to read. I believe we can test the algorithm performance:
inline // better to have FORCEINLINE here
int c_t_z(uint64_t n) {
int zeros = 0;
if (n % 10000000000000000ULL == 0) { zeros += 16; n /= 10000000000000000ULL; }
if (n % 100000000 == 0) { zeros += 8; n /= 100000000; }
if (n % 10000 == 0) { zeros += 4; n /= 10000; }
if (n % 100 == 0) { zeros += 2; n /= 100; }
if (n % 10 == 0) { zeros += 1; }
return zeros;
}
.
.
.
amount >>= zeros;
I am not sure how something like this would perform in comparison with the while
loop. But worth looking at. Code size-wise, of course while
version wins, but performance-wise I would look into the if
implementation [1].
I will ping you on Matrix, to talk about these, even maybe we can work together on this.
Overall everything is clean, and ready to merge after making sure that we are not missing something.
0a37878
to
7e571a0
Compare
Add a performance test suite and used fast power decomposition. Results:Perf test applied to master:
PR:
|
Just out of curiosity, do you have perf numbers for loop version too? Overall it is now very clean. Thanks for considering my suggestion :) |
7e571a0
to
45ad242
Compare
Was just about to test that when you commented lol |
I'm reverting back to the loop after performance testing since the compiler apparently was able to beat me. Using a simple With loop:
|
Includes performance tests
45ad242
to
a79734c
Compare
Great to have the performance test and numbers too. I am fine with loop version too. Overall, everything is good. Running the test locally in few hours, and will approve once the local run finish. |
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.
Test are running correctly too. Thanks.
No description provided.