Atila Neves: "C IS NOT MAGICALLY FAST, PART 2"

Jakob Bornecrantz via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 19 14:17:41 PDT 2016


On Tuesday, 19 July 2016 at 16:13:21 UTC, Atila Neves wrote:
> On Tuesday, 19 July 2016 at 16:01:01 UTC, Lodovico Giaretta 
> wrote:
>> On Tuesday, 19 July 2016 at 15:48:26 UTC, Atila Neves wrote:
>>> Small string optimization should _help_ std::string, no?
>>>
>>> Atila
>>
>> Small string optimization will make the struct bigger, thus 
>> making swapping slower. If the struct is no bigger than 2 
>> pointers, swapping it is ultra fast.
>
> Interesting. Read up on it and tried changing the strings to be 
> ~50 chars long. C++/std::string gets better, but C++/const 
> char* still beats D by a small margin:
>
> C: 1.852s
> C++/std::string: 1.489s
> C++/const char*: 1.034s
> D: 1.188s
>
> Could be the cost of swapping the "fat" in "fat pointer", in 
> which case: worth it.

You are swapping different amount of data.
For C++/const char* vs D, you are swapping 75% more data.
For D vs C++/std::string, you are swsapping 129% more data.

I would expect you getting the same numbers if you did 
"const(char)*" version in D?

And if you used a inline sort[1] in the C version it would 
probably be just as fast as the C++/const char* version.

Also it was a bit hard to find out what N you where using.

Cheers, Jakob.


[1] http://www.corpit.ru/mjt/qsort.html




More information about the Digitalmars-d mailing list