News for hackers. Stuff that matters.
Re:Optimizing uint64_t Digit Counting: A Method that Beats L... by GuB-42 on Wednesday January 08, 2025 @05:58AM (#42632936)
I think it is the case: first allocate the space, then write.

However, I am not sure how significant the gain is here. Actually printing the number requires a division every digit, maybe 2 or 3, which I believe is much slower than even naive digit counting, and you will have to do it eventually.

Maybe it is worth it if there is parallelism involved: write the JSON with blank spaces for the numbers, then have another thread write the numbers. Writing the numbers is computationally expensive because of the divisions, so if you have a lot of large numbers, it may be worth dedicating some cores to this task.

Re:Optimizing uint64_t Digit Counting: A Method that Beats L... by realtimechris on Wednesday January 08, 2025 @08:52AM (#42634189)
No, you only require division for digit-counts greater than or equal to 10: https://github.com/RealTimeChris/Jsonifier/blob/dev/Include/...