[BNM] Advice on Comparing base64 encoded images in PHP please.

paul perrin paul at idltd.com
Mon Jul 2 18:33:52 BST 2007


To be really efficient...

If you can get under the hood of your interpreter, then you may find an
optimisation that allows you to operate on the two strings as a sinlge
processing instruction... comparing long strings should equate to a big
boolean 'and' - something that CPUs excel at :-).

This makes some assumptions on how PHP holds strings etc...

Paul /)/+)

On 02/07/07, John Montgomery <john at littlespikeyland.com> wrote:
>
> > if(md5($imageStr1) != md5($imageStr2))
>
> Is going to compute the md5's for both strings, so if you just want
> to know if the two strings are different it's going to be slower than
> using a strcmp.  Of course if you computed the md5's before hand and
> stored them (and kept them up-to-date) along with the base64 strings
> it would be quicker.
>
> Though, unless you're actually having speed problems you'd be far
> better off just keeping your code simple and sticking with strcmp (or
> surely just a plain old == assuming this is PHP?).
>
> cheers,
>        John
>
> On 2 Jul 2007, at 17:46, joseppi c wrote:
>
> > Hi,
> >
> > I am having to store jpeg Images as base64 encoded strings.
> >
> > I would like to do a comparison between two images to see if they
> > differ.
> >
> > Should I just do a:
> >
> > if(strcmp($imageStr1, $imageStr2))
> > {
> >  //do stuff
> > }
> >
> > Or speed-wise is it better to compare the MD5 result of each string:
> >
> > if(md5($imageStr1) != md5($imageStr2))
> > {
> >  //do stuff
> > }
> >
> > Or does it matter?
> >
> >
> > Thanks,
> >
> > Joe.
> >
> >
> >
> >
> > ___________________________________________________________
> > What kind of emailer are you? Find out today - get a free analysis
> > of your email personality. Take the quiz at the Yahoo! Mail
> > Championship.
> > http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
> > --
> >
> > BNM Subscribe/Unsubscribe:
> > http://www.brightonnewmedia.org/options/bnmlist
> >
> > BNM info/archives:
> > http://www.brightonnewmedia.org/
> >
> > BNM powered by Wessex Networks:
> > http://www.wessexnetworks.com
> >
>
> --
>
> BNM Subscribe/Unsubscribe:
> http://www.brightonnewmedia.org/options/bnmlist
>
> BNM info/archives:
> http://www.brightonnewmedia.org/
>
> BNM powered by Wessex Networks:
> http://www.wessexnetworks.com
>



More information about the BNMlist mailing list. Powered by Wessex Networks