You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When converting numbers to strings string_of_float has a significant performance impact when the number is an INT. Detecting INTs and using string_of_int significantly improves performance. Thus, using
letf2sf=(* Check value is in the JSON integer range, maybe not necessary *)if f >9007199254740991.|| f <-9007199254740991.then string_of_float f
elselet i = int_of_float f inlet f1 = float_of_int i inif f1 = f then string_of_int i
else string_of_float f
Has a cost of around 6.5% for floats but results in around 4x performance improvement for INTs. Here are comparisons of straight string_of_float and f2s for 1,000,000 conversions:
string_of_float
1,552,011,783 cycles
2,958,207,469 instructions
f2s
363,014,703 cycles
945,099,124 instructions
Is it worth integrating this into the encoder?
The text was updated successfully, but these errors were encountered:
It's a bit more complicated on 32-bit platforms (31-bit ints) because the conversion from float to int works on a restricted range (float min_int to float max_int). Here are options I can think of:
use a fixed range regardless of the platform, defined as the range of 31-bit ints;
detect the platform (e.g. using Sys.word_size) and run one function or the other accordingly.
There's also the question of whether this optimization benefits everyone. In some applications, integers may be extremely rare, in which case this "optimization" would slow them down by 6.5% (based on your report).
Atdgen could support a global (command-line) or type-specific option that turns this on or off.
When converting numbers to strings string_of_float has a significant performance impact when the number is an INT. Detecting INTs and using string_of_int significantly improves performance. Thus, using
Has a cost of around 6.5% for floats but results in around 4x performance improvement for INTs. Here are comparisons of straight
string_of_float
andf2s
for 1,000,000 conversions:string_of_float
f2s
Is it worth integrating this into the encoder?
The text was updated successfully, but these errors were encountered: