yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

std::string buffer ctor #191

Closed yakra closed 2 years ago

yakra commented 2 years ago

Problem with constructing a std::string from a raw char* is the computer doesn't immediately know how much space to allocate. It must either...

Both of which waste time. If we know in advance how much space will be needed, let's use this to our advantage.

yakra commented 2 years ago

Waypoint ctor, label & AltLabel construction

./check10.sh -h lab3 --null -v -e -r ReadWpt _clang _2long _buf

numthreads _clang _2long _buf _alt _AInit
11 2.713 1.731 1.701 1.713 1.711
12 2.731 1.634 1.629 1.645 1.641
13 2.722 1.627 1.614 1.624 1.627
14 2.749 1.641 1.627 1.637 1.636
yakra commented 2 years ago

Dynamically (re)allocate as it goes.

This appears to be what happens in any case. Creating an 11-char string with all the constructors yields a 15-char capacity, every time, in both g++ and clang++. Capacity doubles whenever more is needed. Not much harm comes from this; almost all route names & labels are well below this threshold. Standard OSM URLs with 6 decimal places top out right at 60 B, and will only need to reallocate twice. Worse than nothing, but hey.

Performance appears to be marginally worse, right at margin of error.