On Monday, 5 September 2016 at 11:11:23 UTC, Patric wrote:
I´m playing remaking D functionalities with nogc structs, and
to at least match D performance.
But in this particular case i´m unable to get near D
performance.
Can someone point me out what i´m doing wrong, or if there is
some magic behind the curtains on D strings?
https://dpaste.dzfl.pl/1c981fdc71ac
string s;
string a = "testing";
string b = "another";
foreach(_ ; 0..max){
s = a ~ b;
}
Potentially this makes no allocation at all. "testing" and
"another" will be in readonly memory, "a ~ b" will be
constant-folded, and s will get assigned the same slice
every-time.
Now replace it with std::string in C++ and count the number of
malloc ;)