XmacsLabs / lolly

lolly: A user-friendly C++ library
https://xmacslabs.github.io/lolly/
GNU General Public License v3.0
10 stars 6 forks source link

[19_5] improve performance of resize and provide reserve #295

Closed jingkaimori closed 7 months ago

jingkaimori commented 7 months ago

Works

Example

use reserve() along with append operator:

string r;
r.reserve(100);
for(int i=0; i<100; i++){
    r << (i%26) + 'a';
}

Performance

Before

ns/op op/s err% total benchmark
79.08 12,645,769.22 0.8% 0.95 construct string
42.26 23,660,680.56 2.5% 0.71 append string

After

ns/op op/s err% total benchmark
75.58 13,231,790.34 0.9% 0.90 construct string
20.95 47,728,672.38 2.5% 0.47 append string
da-liii commented 7 months ago

Could you explain why we need to add two extra interfaces? Are there similar designs in other C++ string libraries?