Deutsch   English   Français   Italiano  
<9c16141dfe3c785e316678770e965566@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: melahi_ahmed@yahoo.fr (ahmed)
Newsgroups: comp.lang.forth
Subject: Re: Back & Forth - Co-routines
Date: Fri, 31 Jan 2025 12:45:11 +0000
Organization: novaBBS
Message-ID: <9c16141dfe3c785e316678770e965566@www.novabbs.com>
References: <nnd$2fb29a8e$298ef3f8@23fe4f00fa62d734>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="2019686"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="t+/9LUKLIiUqIe6reyFE7me/EcA/Gr17dRXgwnADesE";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 5f6b2e70af503e44dad56966aa15d35bdef29623
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$Blg1BxDdBgzqABz6vN05WefkmWq1c2vNoE1WPcSCslp9fHetbE1XG
Bytes: 3694
Lines: 118

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

--