Re: Loops versus ranges

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 12:20:34 + bearophile via Digitalmars-d-learn wrote: > anon: > > > Changed to > > return data.map!(n => foo2(data, i + 1, > > max)).cache.joiner.array; > > then it produced the same result as array version. > > `map.cache.join` resulted in 597871. > > This is close

Re: Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
anon: Changed to return data.map!(n => foo2(data, i + 1, max)).cache.joiner.array; then it produced the same result as array version. `map.cache.join` resulted in 597871. This is close to tell what the cause is :-) Bye, bearophile

Re: Loops versus ranges

2014-12-19 Thread ketmar via Digitalmars-d-learn
On Fri, 19 Dec 2014 10:41:03 + bearophile via Digitalmars-d-learn wrote: > Can you tell why? :-) 'cause lazy ranges can't be optimised in compile time? ;-) signature.asc Description: PGP signature

Re: Loops versus ranges

2014-12-19 Thread anon via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:41:04 UTC, bearophile wrote: A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) { count1++;

Re: Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
aldanor: On Friday, 19 December 2014 at 10:57:47 UTC, aldanor wrote: Something about the loop in the first case not depending on n and the compiler being able to figure it is out and only drop into recursion once? That's just a wild guess, but does it get transformed into something like this?

Re: Loops versus ranges

2014-12-19 Thread aldanor via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:57:47 UTC, aldanor wrote: Something about the loop in the first case not depending on n and the compiler being able to figure it is out and only drop into recursion once? That's just a wild guess, but does it get transformed into something like this? typeof(r

Re: Loops versus ranges

2014-12-19 Thread aldanor via Digitalmars-d-learn
On Friday, 19 December 2014 at 10:41:04 UTC, bearophile wrote: A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) { count1++;

Loops versus ranges

2014-12-19 Thread bearophile via Digitalmars-d-learn
A case where the usage of ranges (UFCS chains) leads to very bad performance: import std.stdio: writeln; import std.algorithm: map, join; uint count1, count2; const(int)[] foo1(in int[] data, in int i, in int max) { count1++; if (i < max) { typeof(return) result; fore