Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #54561

Re: CASEs compared

From "HAA" <someone@microsoft.com>
Newsgroups comp.lang.forth
Subject Re: CASEs compared
Date 2017-01-31 14:25 +1100
Organization Aioe.org NNTP Server
Message-ID <o6p01m$3sb$1@gioia.aioe.org> (permalink)
References <o6n8ad$191s$1@gioia.aioe.org> <2017Jan30.165616@mips.complang.tuwien.ac.at>

Show all headers | View raw


Anton Ertl wrote:
> "HAA" <someone@microsoft.com> writes:
> >hughaguilar96@gmail.com wrote:
> >> ...
> >> CASE has to be nested IF statements though, which is horribly inefficient.
> >
> >Perhaps not.  Below is some test code for VFX.  It compares IF/ELSE Case with
> >SWITCH from FD 20/3.  The former gave me 10x better speed.
> ...
> This is not the kind of thing Hugh Aguilar has in mind.  Also, the
> point of VanNorman's SWITCH is not performance, but being able to add
> more key-action pairs later; that's why he uses a linked list.

All true but my purpose was to post code as near to the traditional uses of
an IF/ELSE Case.  Hugh may have special needs that rule out Eaker but to
assert it is 'horribly inefficient' is a statement which at the very least needs
qualification.

> And guess what: If we care about performance, we do.  We just don't do
> it by inventing another CASE/SWITCH construct, but we use EXECUTE and
> an xt table; or maybe the whole thing is reorganized:

There are reasons why that isn't used in practice.  To get the speed you
have to be presented with an ideal situation that rarely occurs, you have
to go out of your way to use it, the economics don't stack up when a few
labels/cases are present (which is most of the time), and the thing that's
finally executed will often take more time than the switch itself.

> In Gforth 0.7, we have an intelligent COMPILE, that uses Eaker's CASE
> to decide how to compile each word type.  In the development version,
> each word has a field that says how the word is COMPILE,d, and
> COMPILE, now does something like
>
> : compile, ( xt -- )
>   xt>compile, @ execute ;
>
> And I think that's why there was never much demand for something
> beyond Eaker's CASE.  If there are so many OFs that the linear search
> becomes inefficient, idiomatic Forth programming stops putting all
> that code in a single word.
>
> - anton


Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CASEs compared "HAA" <someone@microsoft.com> - 2017-01-30 22:34 +1100
  Re: CASEs compared anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-01-30 15:56 +0000
    Re: CASEs compared hughaguilar96@gmail.com - 2017-01-30 09:57 -0800
      Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-01-31 14:26 +1100
        Re: CASEs compared hughaguilar96@gmail.com - 2017-01-31 08:12 -0800
          Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-01 11:39 +1100
            Re: CASEs compared hughaguilar96@gmail.com - 2017-01-31 22:37 -0800
              Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 12:26 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 16:50 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-01 18:02 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-02 21:12 +1100
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 13:46 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 17:01 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 12:43 +1100
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:52 -0800
                Re: CASEs compared Alex <alex@rivadpm.com> - 2017-02-04 11:10 +0000
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-02 19:57 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-02 17:05 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-02 21:55 -0500
                Re: CASEs compared Mark Wills <markwills1970@gmail.com> - 2017-02-03 02:11 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 10:52 -0800
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:38 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 22:08 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 21:40 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 01:16 -0500
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 14:40 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-03 17:47 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 22:04 -0500
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 12:39 +1100
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-03 23:32 -0500
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-04 22:50 +1100
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 11:07 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-04 08:48 -0800
                Re: CASEs compared Mark Wills <markwills1970@gmail.com> - 2017-02-04 10:01 -0800
                Re: CASEs compared rickman <gnuarm@gmail.com> - 2017-02-04 16:43 -0500
                Re: CASEs compared hughaguilar96@gmail.com - 2017-02-04 18:53 -0800
                Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-02-05 19:12 +1100
    Re: CASEs compared "HAA" <someone@microsoft.com> - 2017-01-31 14:25 +1100
  Re: CASEs compared Elliott Chapin <elliott.chapin@gmail.com> - 2017-02-05 08:25 -0800
    Re: CASEs compared Coos Haak <htrofhc@gmail.com> - 2017-02-06 00:42 +0100
  Re: CASEs compared jacko <jackokring@gmail.com> - 2017-02-16 17:46 -0800
    Re: CASEs compared hughaguilar96@gmail.com - 2017-02-17 09:09 -0800

csiph-web