Post Reply 
[SOLVED] DSRN (dog slow roman numerals)
06-11-2014, 05:20 PM (This post was last modified: 06-23-2014 07:08 AM by HP67.)
Post: #1
[SOLVED] DSRN (dog slow roman numerals)
This program seems like it takes much longer than it should to run. How long should it take? I have no idea, but not as long as it is taking. I have another program (not shown) that does some string substitution (replacement) and the seat of the pants feeling is it's faster than it should be. I would have thought that scanning for substrings and replacing them with unlike-sized substrings would be one of the more expensive operations. But this simple piece of code that just concatenates a few strings can't get out of its own way.

As you can see there is not a whole lot going on in this code. 1000 tests of converting 2014 (5 while loop executions) to roman numerals in a loop take 970.3 seconds on a 50g on USB power.

Code:
%%HP: T(3)A(R)F(.);
@
@ ( real or int ==> roman numerals )
@
\<< "" SWAP
  WHILE DUP 0 > REPEAT
     CASE 
        DUP 1000 \>= THEN 1000 "M"  END
        DUP  900 \>= THEN  900 "CM" END
        DUP  500 \>= THEN  500 "D"  END 
        DUP  400 \>= THEN  400 "CD" END 
        DUP  100 \>= THEN  100 "C"  END
        DUP   90 \>= THEN   90 "XC" END
        DUP   50 \>= THEN   50 "L"  END
        DUP   40 \>= THEN   40 "XL" END
        DUP   10 \>= THEN   10 "X"  END
        DUP    9 \>= THEN    9 "IX" END
        DUP    5 \>= THEN    5 "V"  END
        DUP    4 \>= THEN    4 "IV" END
        DUP    1 \>= THEN    1 "I"  END
    END
    ROT ROT -
    ROT ROT +
    SWAP
  END DROP

What is the source of the expression "dog slow?" The dogs I had were anything but slow. And even a slow dog is faster than a man can run.

It ain't OVER 'till it's 2 PICK
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[SOLVED] DSRN (dog slow roman numerals) - HP67 - 06-11-2014 05:20 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-11-2014, 07:06 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 11:44 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 04:49 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-15-2014, 12:02 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-16-2014, 06:09 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 05:46 PM



User(s) browsing this thread: 1 Guest(s)