Re: type string

new topic     » topic index » view thread      » older message » newer message

Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> wrote:

>Am I missing something here, but shouldnt any type check routine be
primarly
>optimized for legal values ?

You seem to have misinterpreted my comments as being the primary reason for
discounting Chris Hickman's benchmark results; however, the points I was
making were only secondary. Please (re)read Rod Jackson's "Re: type string"
post previous to mine (the 6th one back) for more details on the primary
reason. Basically, Chris' benchmark program used abnormally long test values
(> 360 chars), which unintentionally biased the results in his routine's
favor. Using shorter strings in the same program, his routine doesn't do
quite so well.


>Illegal value will half of the time halt the program anyway.

Not if you're calling it like a function:

if string(this) then
   -- do something
else
   -- do something else
end if

I'm working on a routine to write Euphoria sequences to a file in compressed
format, and one of the checks I'm performing is to determine whether or not
a given sequence could be stored as a string (which would save a lot of disk
space). This is in one of the *main* loops of my routine, and as such needs
to be as fast as possible. I will very likely encounter a large number of
non-string values before I'm through, so I need a string() routine which
will quit *immediately* once it finds an illegal value.

BTW, I just found the magic "pivot point" between my routine and Chris'. For
string <= 35 chars, my routine is faster. For >= 36, Chris' is faster. This
is, of course, just on my machine -- others may find differing "pivot
points."

Also, these test results are only based on my tinkering with the average
test_set string length in Chris' benchmark program. When I used a generic
binary tree sequence as the test value, Chris' routine ran 90x *slower* than
mine. This is because Chris' routine has to and_bits() the whole sequence --
recursively going through all the subsequences -- before it checks to make
sure all the elements are integers. My routine is much faster in this case,
since it steps thru the sequence one element at a time, and returns 0 as
soon as an illegal value is encountered.


>So, his string routine *is* the fastest. No matter how quick other routines
>spot the illegal one.

Neither routine is "the fastest." It depends on what you're doing, and what
you need to do. For my program, where I frequently call the string type as a
function, I need my string type, since it's optimized for *both* legal and
illegal string values. For other programs, where the string type is
primarily used in object declaration, Chris' would probably be the better
choice, since it's only optimized for legal values (and an illegal value
would cause an abend anyway).


>99% of the processing and the final working program will use legal string
>values anyways.

As I have demonstrated above, this is not always the case.


Be seeing you,
   Gabriel Boehme


 -------
It is terrible to contemplate how few politicians are hanged.

G.K. Chesterton
 -------

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu