New results:

Benchmark: running table, tr, each for at least 3 CPU seconds... table: 4 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 33 +1.84/s (n=1040) tr: 3 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 65 +432.56/s (n=211020) Rate table tr table 332/s -- -99% tr 65433/s 19618% --

(tr is 100x faster than table.)

New Benmark code:

#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); my %rot = ( 'A' => 'N','B' => 'O','C' => 'P','D' => 'Q','E' => 'R','F' => 'S', 'G' => 'T','H' => 'U','I' => 'V','J' => 'W','K' => 'X','L' => 'Y', 'M' => 'Z','N' => 'A','O' => 'B','P' => 'C','Q' => 'D','R' => 'E', 'S' => 'F','T' => 'G','U' => 'H','V' => 'I','W' => 'J','X' => 'K', 'Y' => 'L','Z' => 'M','a' => 'n','b' => 'o','c' => 'p','d' => 'q', 'e' => 'r','f' => 's','g' => 't','h' => 'u','i' => 'v','j' => 'w', 'k' => 'x','l' => 'y','m' => 'z','n' => 'a','o' => 'b','p' => 'c', 'q' => 'd','r' => 'e','s' => 'f','t' => 'g','u' => 'h','v' => 'i', 'w' => 'j','x' => 'k','y' => 'l','z' => 'm', ); sub rot13 ($) { # as close as possible to source project's code join '', map { exists $rot{$_} ? $rot{$_} : $_ } split('',shift); } sub rot13tr ($) { (my $s = shift) =~ tr/a-zA-Z/n-za-mN-ZA-M/; $s; } our $data; { local $/; $data = <DATA>; } cmpthese(-3, { #table => 'use strict; use warnings; my $rv = rot13 (our $data); 1', #tr => 'use strict; use warnings; my $rv = rot13tr(our $data); 1', table => 'my $rv = rot13 ($data); 1', tr => 'my $rv = rot13tr($data); 1', }); __DATA__ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus luctus nulla sed tellus. Sed vitae sapien in elit vestibulum faucibus. Maecenas sollicitudin, magna quis vestibulum convallis, ligula nulla fringilla augue, nec rutrum dolor quam vel justo. Vivamus nisi odio, ullamcorper sed, venenatis id, imperdiet eleifend, neque. Vivamus justo felis, euismod in, convallis auctor, egestas id, purus. In rutrum nisi in lectus. Aliquam elementum placerat dui. Integer ut pede sit amet magna pulvinar placerat. Maecenas massa lorem, lobortis ut, adipiscing at, suscipit nec, lectus. Curabitur mattis adipiscing sem. Mauris pharetra vehicula eros. Sed pellentesque elit laoreet augue. Cras non tellus. Quisque volutpat lectus in sem. Fusce vulputate justo ut pede. Aliquam ante pede, tempor in, dictum in, blandit eu, sapien. Morbi vestibulum, metus eu auctor vulputate, nulla lectus condimentum nisi, ac pulvinar ligula nunc in felis. Curabitur id orci ac est luctus molestie.

In reply to Re: The indisputable speed of tr/// by ikegami
in thread The indisputable speed of tr/// by radiantmatrix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.