gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] ISO Strings.Equal relatively slow


From: SiTex Graphics
Subject: [Gm2] ISO Strings.Equal relatively slow
Date: Mon, 28 Mar 2011 11:31:23 -0700

Hi Gaius,

I recall an earlier thread on this topic, but since it's been a while,
I'll start a new one.

An end-user submitted a case where Strings.Equal became a bottleneck
for our application.  A routine that normally does a few hundred
comparisons was performing millions, and the Equal comparision slowed
our app to a crawl.  Interestingly, this case didn't noticably affect
the performance of the XDS and Stonybrook builds of our application.
I've modified our code to avoid this case, but it still seemed like a
good idea to try to improve the performance of Equal.

Our typical usage is searching a list for a match, and inequality is
by far the most common result.  The code below is written with that
scenario in mind, and it performs much better in my tests than the
existing Equal routine.  Perhaps you'll consider replacing the
existing code with the source below (or perhaps an even faster
version)?

Thanks,
Scott


PROCEDURE Equal (a, b: ARRAY OF CHAR) : BOOLEAN ;
VAR i : CARDINAL ;
BEGIN
  i:=0;
  LOOP
    IF a[i]<>b[i] THEN RETURN FALSE; END;
    IF a[i]=CHR(0) THEN RETURN TRUE; END;
    INC(i);
    IF i>HIGH(a) THEN RETURN (HIGH(a)=HIGH(b)) OR (b[i]=CHR(0)); END;
    IF i>HIGH(b) THEN RETURN a[i]=CHR(0); END;
  END;
END Equal;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]