Re: Back & Forth - Co-routines

Liste des GroupesRevenir à cl forth 
Sujet : Re: Back & Forth - Co-routines
De : mhx (at) *nospam* iae.nl (mhx)
Groupes : comp.lang.forth
Date : 01. Feb 2025, 16:31:01
Autres entêtes
Organisation : novaBBS
Message-ID : <3adbd73998be0586910158459a07a0f7@www.novabbs.com>
References : 1 2
User-Agent : Rocksolid Light
On Fri, 31 Jan 2025 12:45:11 +0000, ahmed wrote:

Hi,
Thanks for this video and this implementation of locals.
>
But what about the speed of execution?
[..]
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?
I had to modify ;: and LOCALE aka LOCAL for iForth
( tail-call optimization is forced off with `[ -OPT ]` ).
The loops here are 1000 x larger (timing goes from ms to seconds)
so that they can be properly compared with your results. However,
the outcome is qualitatively the same: tri-mf4 is 3x worse than
the others. PARAM| is fastest, but it can only shine when
there are less than 3 stack parameters.
: ;: >r [ -OPT ] ;
: locale r> swap dup >r @ >r ;: r> r> ! [ -OPT ] ;
: tri_mf4 ( x a b c -- mf) \ locals new
  c locale b locale a locale
  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
;
defer tri_mf
: test 0 do 20 -50 0 50 tri_mf drop loop ;
: DO-TEST
  CR ." \ The results:"
  CR ." \ tri_mf1: " ['] tri_mf1 [is] tri_mf
     timer-reset #1000000000 test .elapsed  ."   ( 94.866 s)"
  CR ." \ tri_mf2: " ['] tri_mf2 [is] tri_mf
     timer-reset #1000000000 test .elapsed  ."   ( 96.399 s)"
  CR ." \ tri_mf3: " ['] tri_mf3 [is] tri_mf
     timer-reset #1000000000 test .elapsed  ."   ( 83.403 s)"
  CR ." \ tri_mf4: " ['] tri_mf4 [is] tri_mf
     timer-reset #1000000000 test .elapsed  ."  ( 211.670 s)" ;
FORTH> DO-TEST
\ The results:
\ tri_mf1: 3.273 seconds elapsed.  ( 94.866 s)
\ tri_mf2: 2.727 seconds elapsed.  ( 96.399 s)
\ tri_mf3: 2.910 seconds elapsed.  ( 83.403 s)
\ tri_mf4: 8.006 seconds elapsed. ( 211.670 s) ok
The explanation: execution speed is by no means the main goal
of Forth. Who cares about a factor of 30 or 40?
-marcel

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