Post Reply 
Calculator graphics drawing benchmark
01-29-2022, 04:36 PM (This post was last modified: 01-29-2022 08:33 PM by DavidM.)
Post: #22
RE: Calculator graphics drawing benchmark
I like these patterns. It seems like they are much more planned and deliberate than the simple algorithm would imply.

(edit: I removed examples of another approach that created horizontal and vertical dashed lines and replicated those lines in the same randomly-staggered sequence -- they deviated too much from the intended algorithm to include them here)

A "brute force" implementation on the 50g:
Code:
\<<
   R\->B
   \-> s
   \<<
      @ clear/view PICT
      ERASE { #0 #0 } PVIEW

      @ draw horizontal lines
      #0 #79d FOR y
         RAND .5 < s *
         #130d FOR x
            x y
            2. \->LIST
            x s + y
            2. \->LIST
            LINE
         s 2. * STEP
      s STEP

      @ draw vertical lines
      #0 #130d FOR x
         RAND .5 < s *
         #79d FOR y
            x y
            2. \->LIST
            x y s +
            2. \->LIST
            LINE
         s 2. * STEP
      s STEP

      @ leave image on display
      7. FREEZE
   \>>
\>>

This one isn't exactly a speed demon:
HP 50g
program: User RPL
screen: 131x80
time: 13.52s (average of 10 runs)
performance: 775


Given that other platforms were checked with alternate language options, I also tried the above method with System RPL. I knew that a lot of the slowdown in the User RPL implementations comes from type conversions and argument structuring, and both of those would be less of an issue with System RPL.

The brute-force approach I used above in a System RPL implementation looks like this:
Code:
::
   ( 1 arg expected )
   CK1NoBlame

   CK&DISPATCH1
   real ::
      ( setup/clear display )
      ClrDA1IsStat
      RECLAIMDISP
      TURNMENUOFF

      ( convert arg to BINT )
      COERCE {{ s }}

      ( draw horizontal lines )
      EIGHTY ZERO_DO (DO)
         %RAN % .5 %< ITE ONE ZERO s #*
         131 SWAP DO
            INDEX@ JINDEX@
            OVER s #+ JINDEX@
            LINEON
         s #2* +LOOP
      s +LOOP

      ( draw vertical lines )
      131 ZERO_DO (DO)
         %RAN % .5 %< ITE ONE ZERO s #*
         80 SWAP DO
            JINDEX@ INDEX@
            OVER INDEX@ s #+
            LINEON
         s #2* +LOOP
      s +LOOP

      ( abandon LAM )
      ABND

      ( freeze the display )
      SetDAsTemp
   ;
;

A noticeable improvement:
HP 50g
program: System RPL
screen: 131x80
time: 1.459s (average of 10 runs)
performance: 7,183

Thanks for the interesting exercise!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Calculator graphics drawing benchmark - DavidM - 01-29-2022 04:36 PM



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