Just playing with compiler explorer to see assembly line count.
Daniel Kozak
kozzi11 at gmail.com
Tue Oct 3 17:15:04 UTC 2017
is not bad
https://godbolt.org/g/bSfubs
On Tue, Oct 3, 2017 at 3:19 PM, SrMordred via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> //D compiled with gdc 5.2 -O3
>
> auto test(int[] arr, int cmp)
> {
> int[] r;
> foreach(v ; arr)
> if(v == cmp)r~=v;
> return r;
> }
> // 51 lines of assembly
>
> auto test(int[] arr, int cmp)
> {
> return arr.filter!((v)=>v==cmp).array;
> }
> //1450 lines... what?
>
> Ok let me look also at c++:
> //gcc 7.2 -O3
>
> vector<int> test(vector<int>& arr, int cmp) {
> vector<int> r;
> for(auto v : arr)
> if(v == cmp)r.push_back(v);
> return r;
> }
> //152 lines. more than D :)
>
> vector<int> test(vector<int>& arr, int cmp) {
> vector<int> r;
> std::copy_if (arr.begin(), arr.end(), std::back_inserter(r),
> [cmp](int i){return i==cmp;} );
> return r;
> }
>
> //150 lines. That what i expected earlier with D.
>
> Hmm. let me be 'fair' and use std.container.array just for curiosity:
>
> auto test(ref Array!int arr, int cmp)
> {
> Array!int r;
> foreach(v ; arr)
> if(v == cmp)r.insert(v);
> return r;
> }
>
> //5542 lines... what??
>
> Someone interested to discuss about this?
>
> Or point me some grotesque mistake.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20171003/2764aa6b/attachment.html>
More information about the Digitalmars-d
mailing list