<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&nbsp;<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">&nbsp; ;; perform a single rearrangement</font></div><div><font class="Apple-style-span" color="#001f54">&nbsp;</font><font class="Apple-style-span" color="#0045a3"> (define (single-flip source result count)</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; (if [= count 0]</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; &nbsp; &nbsp; result</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; &nbsp; &nbsp; (single-flip (cdr source) (cons (car source) result) (sub1 count)))) &nbsp; &nbsp; </font><font class="Apple-style-span" color="#001f54">&nbsp;</font></div><div><font class="Apple-style-span" color="#7a7a7a">&nbsp; ;; flip until (car lst) is 1</font></div><div><font class="Apple-style-span" color="#001f54">&nbsp; </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">&nbsp; &nbsp; (let ([l (car lst)])</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; &nbsp; (if [= l 1]</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; number-of-flips</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (multi-flip (single-flip lst (drop lst l) l) (add1 number-of-flips))))) &nbsp;</font></div><div><font class="Apple-style-span" color="#0045a3">&nbsp; (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>