<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi all,<div><br></div><div>I've implemented the 'pfannkuchen' algorithm for the fannkuch-redux benchmark on <a href="http://shootout.alioth.debian.org">shootout.alioth.debian.org</a>, since this is the only remaining benchmark without a Racket attempt. It seemed like a fun newbie project.</div><div><br></div><div>I'd appreciate any optimization hints or general comments and criticism of my coding. The full code is at <a href="https://github.com/cbowdon/Fannkuch-Redux">https://github.com/cbowdon/Fannkuch-Redux</a>.</div><div><br></div><div>In terms of optimization, the worst offender is the following function:</div><div><br></div><div><div><font class="Apple-style-span" color="#7a7a7a">;; perform flipping on a single permutation, return number of flips</font></div><div><font class="Apple-style-span" color="#0045a3">(define (fannkuch input)</font></div><div><font class="Apple-style-span" color="#7a7a7a"> ;; perform a single rearrangement</font></div><div><font class="Apple-style-span" color="#001f54"> </font><font class="Apple-style-span" color="#0045a3"> (define (single-flip source result count)</font></div><div><font class="Apple-style-span" color="#0045a3"> (if [= count 0]</font></div><div><font class="Apple-style-span" color="#0045a3"> result</font></div><div><font class="Apple-style-span" color="#0045a3"> (single-flip (cdr source) (cons (car source) result) (sub1 count)))) </font><font class="Apple-style-span" color="#001f54"> </font></div><div><font class="Apple-style-span" color="#7a7a7a"> ;; flip until (car lst) is 1</font></div><div><font class="Apple-style-span" color="#001f54"> </font><font class="Apple-style-span" color="#0045a3">(define (multi-flip lst number-of-flips)</font></div><div><font class="Apple-style-span" color="#0045a3"> (let ([l (car lst)])</font></div><div><font class="Apple-style-span" color="#0045a3"> (if [= l 1]</font></div><div><font class="Apple-style-span" color="#0045a3"> number-of-flips</font></div><div><font class="Apple-style-span" color="#0045a3"> (multi-flip (single-flip lst (drop lst l) l) (add1 number-of-flips))))) </font></div><div><font class="Apple-style-span" color="#0045a3"> (multi-flip input 0))</font></div></div><div><br></div><div>Any advice? Profiling suggested that 70% of time is spent in this function.</div><div><br></div><div>Best regards,</div><div>Chris</div><div><br></div><div><div>P.S. Kindly note that this is a question about some code, not a meta-discussion on computer language benchmarks etc.</div><div><br></div></div></body></html>