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
String.replaced is an alias of map_unlikely. This names makes the intent
of the function clearer. Because a function to replace the characters is
exposed, users are less likely to fall into the pitfall of using lists.
Lists not only are very slow, but allow users to have more than one
replacement rule per character, possibly introducing mistakes.
If a plain match function cannot be produced and a list needs to be used,
users can convert it to a Char.Map and do the match with a find_opt.
This approach ends up being ~60-70% faster than using plain lists.
The benchmark comparing the new approach with the old one:
String size 100:
Optimized: 236.556 μs
Reference: 1861.600 μs
Improvement: 87.3% faster
String size 500:
Optimized: 1099.030 μs
Reference: 9665.405 μs
Improvement: 88.6% faster
String size 1000:
Optimized: 2198.777 μs
Reference: 19115.019 μs
Improvement: 88.5% faster
Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
0 commit comments