May the numbers speak

Liste des GroupesRevenir à cl forth 
Sujet : May the numbers speak
De : zbigniew2011 (at) *nospam* gmail.com (LIT)
Groupes : comp.lang.forth
Date : 11. Jun 2025, 14:54:53
Autres entêtes
Organisation : novaBBS
Message-ID : <20129e22c76a2b18b0a745e9499cbd9b@www.novabbs.com>
User-Agent : Rocksolid Light
Let's find out the difference between my
and "Mark Twain" 's approach to the solution
of "parsing 'time string' task". For simplicity
I'll do everything using DX Forth.
My solution is:
VARIABLE C6
VARIABLE C1
: TIMESTRSCAN ( addr count -- d )
  1 C6 !  1 C1 !
  >R >R 0 0 R> R>
  OVER + 1-
  DO
    I C@ DUP 58 =
    IF
      DROP
      C6 @ 60 * C6 !
      1 C1 !
    ELSE
      48 - C1 @ * C6 @ M* D+
      10 C1 !
    THEN
  -1 +LOOP
;
(the only change for ANS-Forth were
 slightly different two VARIABLE lines,
 I have no idea what kind of problem Ed
 met with the loop)
Mr. Fifo's proposal:
: dtimescan
   over swap chars + >r >r 0. r> 0 begin
     over r@ <
   while
     over c@ [char] : =
     if
       swap >r s>d d+ 60 1 m*/ r> 0
     else
       10 * over c@ [char] 0 - +
     then
     swap char+ swap
   repeat r> drop nip s>d d+
;
OK, now we need to time both solutions.
So let's create the timing words:
: TLOOP1
  TICKS PAD 8 30000 0 DO 2DUP TIMESTRSCAN 2DROP LOOP
  2DROP TICKS 2SWAP D- D. ;
: TLOOP2
  TICKS PAD 8 30000 0 DO 2DUP dtimescan 2DROP LOOP
  2DROP TICKS 2SWAP D- D. ;
Now let's take it away:
S" 12:34:56" PAD SWAP CMOVE  ok
TLOOP1 61  ok
TLOOP2 10  ok
Ooops! Not too good. It seems variables are
pretty "expensive" thing in DX Forth. So let's
optimize the thing a little, quite basic way:
: TIMESTRSCAN1 ( addr count -- d )
  1 C6 !  1 C1 !
  >R >R 0 0 R> R>
  OVER + 1-
  DO
    I C@ DUP 58 =
    IF
      DROP
      [ C6 ] LITERAL @ 60 * [ C6 ] LITERAL !
      1 [ C1 ] LITERAL !
    ELSE
      48 - [ C1 ] LITERAL @ * [ C6 ] LITERAL @ M* D+
      10 [ C1 ] LITERAL !
    THEN
  -1 +LOOP
;
: TLOOP3
  TICKS PAD 8 30000 0 DO 2DUP TIMESTRSCAN1 2DROP LOOP
  2DROP TICKS 2SWAP D- D. ;
How does it do now?
S" 12:34:56" PAD SWAP CMOVE  ok
TLOOP3 16  ok
So according to the rule: "Once twp implementation
 techniques provide performance within (say)
 a factor of 1.5 or 2 of each other, I stop worrying.
 Short words are better than long ones." - I still
dare to express the opinion my solution is better.
Besides: only recently some "Master of Forth" explained:
"you have to know that good software comes with MANY
 qualities, speed being only one of them. If I have to
 choose between correct and fast, there has to be a very
 convincing argument for the speed requirement.
 They didn't tell you that in your college? Oh dear. I'm
 so sorry for you! You must have had a miserable life."
So taking the above into consideration, the
slightly slower pace of my (optimized) solution
doesn't really matter. No further optimization
really necessary, in fact.
--

Date Sujet#  Auteur
11 Jun 25 * May the numbers speak32LIT
11 Jun 25 +* Re: May the numbers speak25LIT
11 Jun 25 i`* Re: May the numbers speak - supplement24LIT
11 Jun 25 i `* Re: May the numbers speak - supplement23minforth
12 Jun 25 i  `* Re: May the numbers speak - supplement22dxf
12 Jun 25 i   `* Re: May the numbers speak - supplement21Paul Rubin
12 Jun 25 i    +- Re: May the numbers speak - supplement1LIT
12 Jun 25 i    +* Re: May the numbers speak - supplement8mhx
12 Jun 25 i    i`* Re: May the numbers speak - supplement7Paul Rubin
12 Jun 25 i    i +* Re: May the numbers speak - supplement5mhx
12 Jun 25 i    i i`* Re: May the numbers speak - supplement4Paul Rubin
13 Jun 25 i    i i `* Re: May the numbers speak - supplement3mhx
13 Jun 25 i    i i  `* Re: May the numbers speak - supplement2Paul Rubin
13 Jun 25 i    i i   `- Re: May the numbers speak - supplement1mhx
13 Jun 25 i    i `- Re: May the numbers speak - supplement1dxf
12 Jun 25 i    +- Re: May the numbers speak - supplement1ahmed
12 Jun 25 i    +- Re: May the numbers speak - supplement1minforth
12 Jun 25 i    +* Re: May the numbers speak - supplement2B. Pym
12 Jun 25 i    i`- Re: May the numbers speak - supplement1Paul Rubin
12 Jun 25 i    +- Re: May the numbers speak - supplement1peter
12 Jun 25 i    `* Re: May the numbers speak - supplement6B. Pym
13 Jun 25 i     `* Re: May the numbers speak - supplement5dxf
13 Jun 25 i      +* Re: May the numbers speak - supplement3Hans Bezemer
13 Jun 25 i      i`* Re: May the numbers speak - supplement2Paul Rubin
14 Jun 25 i      i `- Re: May the numbers speak - supplement1dxf
15 Jun 25 i      `- Re: May the numbers speak - supplement1dxf
11 Jun 25 `* Re: May the numbers speak6dxf
11 Jun 25  `* Re: May the numbers speak5Hans Bezemer
12 Jun 25   +- Re: May the numbers speak1dxf
12 Jun 25   `* Re: May the numbers speak3sean
12 Jun 25    +- Re: May the numbers speak1mhx
12 Jun 25    `- Re: May the numbers speak1minforth

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal