in reply to Re: Fast search/replace?
in thread Fast search/replace?

This is a *little* faster. Why? But it's still not fast enough. I'm working on an image (320x240), and this is not pretty (5+ minutes for each test). Maybe I should look into using a 1D array?
--Toby.

Replies are listed 'Best First'.
Re: Re: Re: Fast search/replace?
by chromatic (Archbishop) on Feb 14, 2001 at 01:58 UTC
    If you're performing matrix operations, the PDL module may come in handy. Otherwise, working with images, you may have more luck with Image::Magick.

    Either approach will use C code, which is likely many times faster for this operation.

Re: Re: Re: Fast search/replace?
by MeowChow (Vicar) on Feb 14, 2001 at 05:53 UTC
    Constructing an image with list values representing individual pixels is a bit like making a cake by assembling crumbs.

    Even a 1-dimensional array will not provide any acceptable level of performance for this task. There's just alot of overhead involved in processing list values, as compared with a raw buffer.

    If none of the suggested image modules do what you are looking for, I would first recommend that you store and modify your image in place, as a raw scalar stream of bytes. If you're simply trying to swap byte A with byte B, applying the tr/// operator will probably suffice, as it uses an efficient table-lookup technique. If you need to swap 16-bit or larger words, the s/// operator may also offer an acceptable level of performance, but won't come close to what you could do with optimized assembler or C code.

    Manipulating raw buffers in an efficient manner is not one of Perl's strengths :|

       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: Re: Re: Fast search/replace?
by arturo (Vicar) on Feb 14, 2001 at 01:57 UTC

    If you must do it in Perl, maybe. But if you're processing an image, maybe you want to look into Image::Magick. Or maybe you want to write this routine in C / XS?

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: Re: Re: Fast search/replace?
by extremely (Priest) on Feb 14, 2001 at 13:24 UTC
    Maybe think about storing the data in a single string and working it with vec. Vec can be sexy fast on certain tasks. OTOH, Perl isn't your friend when it comes to too much bit-twiddling. You likely should take the other's advice and look at Image::Magick or PDL. You'll be happier in the end if you can job image creation out to C routines.

    --
    $you = new YOU;
    honk() if $you->love(perl)