The converter version seems faster, according to Criterium :
(crit/quick-bench (string-compression-2 "aaabccdddd")) Execution time mean : 6.150477 ยตs Execution time std-deviation : 246.740784 ns Execution time lower quantile : 5.769961 ยตs ( 2.5%) Execution time upper quantile : 6.398563 ยตs (97.5%) Overhead used : 1.620718 ns (crit/quick-bench (string-compression-3 "aaabccdddd")) Execution time mean : 2.533919 ยตs Execution time std-deviation : 157.594154 ns Execution time lower quantile : 2.341610 ยตs ( 2.5%) Execution time upper quantile : 2.704182 ยตs (97.5%) Overhead used : 1.620718 ns
As coredump noted, the sample size of one is not enough to say whether one approach is faster than the other.
source share