Re: Back & Forth - Co-routines

Liste des GroupesRevenir à cl forth 
Sujet : Re: Back & Forth - Co-routines
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forth
Date : 31. Jan 2025, 13:45:11
Autres entêtes
Organisation : novaBBS
Message-ID : <9c16141dfe3c785e316678770e965566@www.novabbs.com>
References : 1
User-Agent : Rocksolid Light
Hi,
Thanks for this video and this implementation of locals.
But what about the speed of execution?
I've written this test ( calculte the membership function, fuzzy logic)
using:
--stack juggling, the word: tri_mf1
--global variables, the word: tri_mf2
--local variables, (gforth), the word: tri_mf3
--local variables, using this method presented here, the word: tri_mf3
the program is here after (using gforth):
: tri_mf1 ( x a b  c -- mf) \ stack juggling
  >r >r ( x a ) ( r: c b)
  2dup < if rdrop rdrop 2drop 0 exit then
  ( x a) ( r: c b)
  over ( x a x ) ( r: c b)
  r@ ( x a x b) ( r: c b)
  <
  >r
  2dup >=
  r> and ( x a t) ( r: c b)
  if ( x a) ( r: c b)
     tuck ( a x a)
     - 100 ( a x-a 100) ( r: c b)
     rot ( x-a 100 a ) ( r: c b)
     r>  ( x-a 100 a b) ( r: c)
     swap - ( x-a 100 b-a) ( r: c)
     */ rdrop exit
  then
  ( x a ) ( r: c b)
  drop ( x) ( r: c b)
  r@ 2dup ( x b x b) ( r: c b )
  >=      ( x b t)   ( r: c b)
  rdrop  ( x b t ) ( r: c)
  >r ( x b ) ( r: c t)
  over ( x b x ) ( r: c t)
  r>   ( x b x t) ( r: c)
  r@   ( x b x t c ) ( r: c)
  swap ( x b x c t) ( r: c)
  >r ( x b x c) ( r: c t)
  < r> and ( x b t) ( r: c)
  if ( x b) ( r: c)
     r@ ( x b c) ( r: c)
     rot - ( b c-x) ( r: c)
     100 ( b c-x 100) ( r: c)
     rot ( c-x 100 b ) ( r: c)
     r> swap - */ exit then
  2drop rdrop
  0
;
variable a
variable b
variable c
: tri_mf2 ( x a b c -- mf)  \ global variables
  c ! b ! a !
  dup a @ < if drop 0 exit then
  dup a @ >= over b @ < and if a @ - 100 b @ a @ - */ exit then
  dup b @ >= over c @ < and if c @ swap - 100 c @ b @ - */ exit then
  drop 0
;
: tri_mf3 ( x a b c -- mf) { a b c -- } \ locals à la gforth
  dup a < if drop 0 exit then
  dup a >= over b < and if a - 100 b a - */ exit then
  dup b >= over c < and if c swap - 100 c b - */ exit then
  drop 0
;
: ;: >r ;
: local r> swap dup >r @ >r ;: r> r> ! ;
variable a
variable b
variable c
: tri_mf4 ( x a b c -- mf) \ locals new
  a local b local c local
  c ! b ! a !
  dup a @ < if drop 0 exit then
  dup a @ >= over b @ < and if a @ - 100 b @ a @ - */ exit then
  dup b @ >= over c @ < and if c @ swap - 100 c @ b @ - */ exit then
  drop 0
;
for the test I use:
defer tri_mf
: test 0 do 20 -50 0 50 tri_mf drop loop ;
The results:
' tri_mf1 is tri_mf  ok
timer-reset 1000000 test .elapsed  94.866300ms  ok
' tri_mf2 is tri_mf  ok
timer-reset 1000000 test .elapsed  96.399100ms  ok
' tri_mf3 is tri_mf  ok
timer-reset 1000000 test .elapsed  83.403500ms  ok
' tri_mf4 is tri_mf  ok
timer-reset 1000000 test .elapsed 211.670300ms  ok
I see that the proposed method is slower than the others
Any explainations?
Ahmed
--

Date Sujet#  Auteur
31 Jan 25 * Re: Back & Forth - Co-routines12ahmed
31 Jan 25 +* Re: Back & Forth - Co-routines2ahmed
31 Jan 25 i`- Re: Back & Forth - Co-routines1ahmed
31 Jan 25 +- Re: Back & Forth - Co-routines1ahmed
31 Jan 25 +- Re: Back & Forth - Co-routines1ahmed
31 Jan 25 +* Re: Back & Forth - Co-routines6Paul Rubin
1 Feb 25 i+* Re: Back & Forth - Co-routines2ahmed
1 Feb 25 ii`- Re: Back & Forth - Co-routines1ahmed
1 Feb 25 i`* Re: Back & Forth - Co-routines3Anton Ertl
1 Feb 25 i `* Re: Back & Forth - Co-routines2ahmed
1 Feb 25 i  `- SELECT (was: Back & Forth - Co-routines)1Anton Ertl
1 Feb 25 `- Re: Back & Forth - Co-routines1mhx

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal