I came across FFI::TinyCC and FFI::Platypus recently. The Alien::TinyCC module is what compiles the C code and does so very quickly in memory.

This demonstration completes in 1.832 seconds, ahead of tr.

use strict; use warnings; use Time::HiRes qw( time ); # ------------------------------------------------------------------- use FFI::TinyCC; use FFI::Platypus::Declare qw( string int ); my $tcc = FFI::TinyCC->new; $tcc->compile_string (q{ int filter_str ( char* str ) { char* p = str; int i = 0; /* strip chars in-place */ while ( *str ) { if ( *str == '[' || *str == ']' || *str == '\'' ) { str++; continue; } *p++ = *str++; i++; } return i; } }); my $address = $tcc->get_symbol('filter_str'); attach [ $address => 'filter_str' ] => [ string ] => int; # ------------------------------------------------------------------- my $doc = "'C-3PO' or 'See-Threepio' is a humanoid robot character fro +m the [[Star Wars]] universe who appears in the original ''Star Wars' +' films, the prequel trilogy and the sequel trilogy.\n"; $doc .= $doc for 1 .. 22; ## expand string to 724 MB my $doclen = length $doc; print "length : $doclen\n"; ## 759169024 my $start = time; my $newlen = filter_str($doc); ## resize string to its new length substr $doc, $newlen, $doclen - $newlen, ''; printf "duration : %7.03f secs.\n", time - $start; print "length : $newlen\n"; ## 708837376


Well, curiosity got to me and the reason for trying TinyCC for the first time :)


In reply to Re^2: Remove double bracket and singe quotes by marioroy
in thread Remove double bracket and singe quotes by lobs

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.