digitalmars.D.learn - Stride in foreach ranges
- Paul Jurczak (9/9) Aug 29 2013 Is there a better way to express a range with stride than this:
- Namespace (7/16) Aug 30 2013 That is strange because the FAQ says here:
- Paul Jurczak (2/23) Aug 30 2013 It's there at: http://dpaste.dzfl.pl/2cf504db
- Paul Jurczak (16/19) Aug 30 2013 I'm not sure what are the compiler switches on DPaste and I don't
- Dicebot (4/6) Aug 30 2013 This pretty much shows that there is nothing wrong in language
- Paul Jurczak (3/9) Aug 30 2013 DMD code generation is very good with for loops, not so good with
Is there a better way to express a range with stride than this: foreach (i; iota(0, N, 2)) foreach (i; 0..2..N) I found this thread suggesting syntax improvement http://forum.dlang.org/thread/bug-4112-3 http.d.puremagic.com/issues/ but I don't think it produced any results. BTW, DMD produces faster code when for loop is used instead, with GDC it makes no difference.
Aug 29 2013
On Friday, 30 August 2013 at 06:31:39 UTC, Paul Jurczak wrote:Is there a better way to express a range with stride than this: foreach (i; iota(0, N, 2)) foreach (i; 0..2..N) I found this thread suggesting syntax improvement http://forum.dlang.org/thread/bug-4112-3 http.d.puremagic.com/issues/ but I don't think it produced any results. BTW, DMD produces faster code when for loop is used instead, with GDC it makes no difference.That is strange because the FAQ says here: http://dlang.org/faq.html#foreach "[...]let the compiler do the optimization." and "Let the compiler pick!" Can you prove this on DPaste?
Aug 30 2013
On Friday, 30 August 2013 at 14:11:06 UTC, Namespace wrote:On Friday, 30 August 2013 at 06:31:39 UTC, Paul Jurczak wrote:It's there at: http://dpaste.dzfl.pl/2cf504dbIs there a better way to express a range with stride than this: foreach (i; iota(0, N, 2)) foreach (i; 0..2..N) I found this thread suggesting syntax improvement http://forum.dlang.org/thread/bug-4112-3 http.d.puremagic.com/issues/ but I don't think it produced any results. BTW, DMD produces faster code when for loop is used instead, with GDC it makes no difference.That is strange because the FAQ says here: http://dlang.org/faq.html#foreach "[...]let the compiler do the optimization." and "Let the compiler pick!" Can you prove this on DPaste?
Aug 30 2013
On Friday, 30 August 2013 at 17:19:11 UTC, Paul Jurczak wrote:On Friday, 30 August 2013 at 14:11:06 UTC, Namespace wrote:[..]I'm not sure what are the compiler switches on DPaste and I don't see an option to change them, so here are my measurements: Windows 7 64-bit Core i5 2500 3.4GHz turbo: DMD 2.063.2 (32-bit): dmd -O -noboundscheck -inline -release 669171001 622ns e28_0 669171001 1244ns e28_1 Xubuntu 13.04 64-bit Core i5 3450S 2.8GHz (3.5GHz turbo): GDC 4.8.1: gdc -m64 -march=native -fno-bounds-check -frename-registers -frelease -O3 669171001 1455ns e28_0 669171001 1458ns e28_1 DMD64 2.063.2: dmd -O -noboundscheck -inline -release 669171001 891ns e28_0 669171001 1572ns e28_1Can you prove this on DPaste?It's there at: http://dpaste.dzfl.pl/2cf504db
Aug 30 2013
On Friday, 30 August 2013 at 06:31:39 UTC, Paul Jurczak wrote:BTW, DMD produces faster code when for loop is used instead, with GDC it makes no difference.This pretty much shows that there is nothing wrong in language with current iota approach and it is simply problem of bad dmd code generation.
Aug 30 2013
On Friday, 30 August 2013 at 14:18:22 UTC, Dicebot wrote:On Friday, 30 August 2013 at 06:31:39 UTC, Paul Jurczak wrote:DMD code generation is very good with for loops, not so good with foreach (see my timings in previous post).BTW, DMD produces faster code when for loop is used instead, with GDC it makes no difference.This pretty much shows that there is nothing wrong in language with current iota approach and it is simply problem of bad dmd code generation.
Aug 30 2013