Re: Ruby Turing Machine (quiz #24 solution)

Andrew Dalke <dalke-DxsMES/F/[email protected]> Fri, 17 Sep 2004 09:49:50 -0600
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
For funsies I took James Edward Gray II's Ruby solution, my unpublished
Python solution, and Bill Tucker's early (*ahem* :) Perl solution and
ran my stack program on them to compute 5**3.  They all gave the same
answer (wc gives +1 because of the \n).  The Perl code was that fastest,
Ruby the slowest.

% /usr/bin/time perl turing.pl stackm.tm '11111PDMDM' | wc
         6.21 real         6.06 user         0.05 sys
        1       1     626
% /usr/bin/time python turing.py stackm.tm '11111PDMDM' | wc
         8.69 real         8.45 user         0.10 sys
        1       1     626
% /usr/bin/time ruby turing.rb stackm.tm '11111PDMDM' | wc
        17.10 real        16.36 user         0.07 sys
        1       1     626


My Python, like the Ruby, uses a class for the tape and I suspect
the biggest hit comes from method call overhead.

					Andrew
					dalke-DxsMES/F/[email protected]