Re: Reflections on isPalindrome

2014-10-29 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 16:07:38 UTC, MachineCode wrote: I'm very surprise. If they either equal or fast sometimes the compiler did great optizations or it's just a multicore processor that's helping or what else? the first version (from your post, the one using ranges) change in each

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
Hi, I don't know if I'm missing something but I did some tests with the popFront and popBack version: bool isPalindrome(R)(R range) if (isBidirectionalRange!(R)) { while (!range.empty){ if (range.front != range.back) return false; range.popFront();

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 11:48:37 UTC, MattCoder wrote: And in my benchmark test, the first version is 3x slower than the second one. I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Matheus.

Re: Reflections on isPalindrome

2014-10-28 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 27 October 2014 at 22:53:57 UTC, Nordlöw wrote: Why bidirectional range only? popBack() only for I mean: you should write a different version for non-bidirectional ranges too :)

Re: Reflections on isPalindrome

2014-10-28 Thread Nordlöw
On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote: I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Try compiling with DMD flag -release and perhaps also -release -noboundscheck to get relevant results. DMD is currently not that good at

Re: Reflections on isPalindrome

2014-10-28 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 13:30:05 UTC, Nordlöw wrote: On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote: I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Try compiling with DMD flag -release and perhaps also -release -noboundscheck to

Re: Reflections on isPalindrome

2014-10-28 Thread Nordlöw
On Tuesday, 28 October 2014 at 14:09:50 UTC, MattCoder wrote: Now with: -release -noboundscheck they are equal and sometimes your version is slightly faster by ~3 milliseconds. That is great to hear! You should try profiling with ldc aswell.

Re: Reflections on isPalindrome

2014-10-28 Thread MachineCode via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 14:09:50 UTC, MattCoder wrote: On Tuesday, 28 October 2014 at 13:30:05 UTC, Nordlöw wrote: On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote: I forgot to say that I'm compiling with DMD without any compiler hints/optimizations. Try compiling with DMD

Re: Reflections on isPalindrome

2014-10-27 Thread via Digitalmars-d-learn
On Sunday, 26 October 2014 at 20:38:29 UTC, Nordlöw wrote: On Friday, 24 October 2014 at 22:29:12 UTC, Peter Alexander wrote: Further, I would like to extend isPalindrome() with a minimum length argument minLength that for string and wstring does I extended my algorithm with a minLength

Re: Reflections on isPalindrome

2014-10-27 Thread Nordlöw
On Monday, 27 October 2014 at 12:10:59 UTC, Marc Schütz wrote: You could add an early `return false;` if the range has length and it is less than minLength. See update :) Thanks!

Re: Reflections on isPalindrome

2014-10-27 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 27 October 2014 at 16:59:19 UTC, Nordlöw wrote: On Monday, 27 October 2014 at 12:10:59 UTC, Marc Schütz wrote: You could add an early `return false;` if the range has length and it is less than minLength. See update :) Thanks! And you can return true if length = 1 Why

Re: Reflections on isPalindrome

2014-10-27 Thread Nordlöw
On Monday, 27 October 2014 at 21:28:17 UTC, Andrea Fontana wrote: And you can return true if length = 1 Thanks. Why bidirectional range only? popBack() only for http://dlang.org/phobos/std_range.html#isBidirectionalRange

Re: Reflections on isPalindrome

2014-10-26 Thread Nordlöw
On Friday, 24 October 2014 at 22:29:12 UTC, Peter Alexander wrote: Further, I would like to extend isPalindrome() with a minimum length argument minLength that for string and wstring does I extended my algorithm with a minLength argument

Re: Reflections on isPalindrome

2014-10-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 24, 2014 at 09:56:18PM +, Nordlöw via Digitalmars-d-learn wrote: I would appreciate comments on my palindrome predicate function bool isPalindrome(R)(in R range) @safe pure if (isBidirectionalRange!(R)) { import std.range: retro, take; import std.algorithm:

Re: Reflections on isPalindrome

2014-10-24 Thread Peter Alexander via Digitalmars-d-learn
On Friday, 24 October 2014 at 21:56:20 UTC, Nordlöw wrote: bool isPalindrome(R)(in R range) @safe pure Aside: for templates, just let the compiler infer @safe and pure. You don't know whether the range operations on R are pure or not. As for the actual algorithm, there's no need for the

Re: Reflections on isPalindrome

2014-10-24 Thread Nordlöw
On Friday, 24 October 2014 at 22:29:12 UTC, Peter Alexander wrote: On Friday, 24 October 2014 at 21:56:20 UTC, Nordlöw wrote: bool isPalindrome(R)(in R range) @safe pure Aside: for templates, just let the compiler infer @safe and pure. You don't know whether the range operations on R are