Announcement

Collapse
No announcement yet.

slow register variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by Bud Durland View Post
    I'm very much shooting from the hip here, but what if you use

    Code:
    k = 7&
    I think we have a record. A possible solution posted more that 11 years after a question

    Comment


    • #22
      Originally posted by Stuart McLachlan View Post
      I think we have a record. A possible solution posted more that 11 years after a question
      11 years might be a necroposting record.

      Comment


      • #23
        It's because the font with the posting date is very small, and although I have a pair of glasses, my curiosity hasn't overcome my vanity.
        Real programmers use a magnetized needle and a steady hand

        Comment


        • #24
          Lets see, after 11 Years I believe this topic ist still of interest.

          Let's try this one is without REGISTER Variables ...

          Code:
          FUNCTION PBMAIN () AS LONG
          
          LOCAL tc AS LONG
          #REGISTER NONE
          '=====================================================================
          
                  tc = GetTickCount()
          
                 LOCAL k AS LONG, i AS LONG
                 LOCAL  j AS LONG
          
                  FOR i = 1 TO 30000
                  FOR j = 1 TO 30000
                  k+=7
                  NEXT j
                  NEXT i
          
               ? STR$(GetTickCount - tc)
          
          END FUNCTION
          
          '=====================================================================
          RESULT: 2000 Ticks

          Now we use REGISTER Variables.
          Should it be faster?

          Code:
          FUNCTION PBMAIN () AS LONG
          
          LOCAL tc AS LONG
          
          '=====================================================================
          
                  tc = GetTickCount()
          
                 REGISTER i AS LONG, j AS LONG
                 LOCAL  k AS LONG 
          
                  FOR i = 1 TO 30000
                  FOR j = 1 TO 30000
                  k+=7
                  NEXT j
                  NEXT i
          
               ? STR$(GetTickCount - tc)
          
          END FUNCTION
          
          '=====================================================================        
          END FUNCTION
          RESULT: 2047 Ticks

          It's even slower!

          Maybe because of some Details of the FOR-LOOP.

          If you do not want to pay the "47 Ticks", just use a DO ... LOOP and IF.

          Now lets unleash the REAL POWER of PB REGISTER Variables!

          By placing "k" into the REGISTER and removing "i".


          Code:
               FUNCTION PBMAIN () AS LONG
          
          LOCAL tc AS LONG
          
          '=====================================================================
          
                  tc = GetTickCount()
          
                 REGISTER k AS LONG, j AS LONG
                 LOCAL  i AS LONG  
          
                  FOR i = 1 TO 30000
                  FOR j = 1 TO 30000
                  k+=7
                  NEXT j
                  NEXT i
          
               ? STR$(GetTickCount - tc)
          
          END FUNCTION
          
          '=====================================================================

          RESULT: 516 Ticks USING PB REGISTER Variables!
          Thats 4 times as fast as without using the REGISTER Variables!

          Using the Loop-Variables as a REGISTER Variable is only good, if the Loop Variable is also often used inside the Loop.

          Best is, if you put the most often accessed Variable into the REGISTER.
          Last edited by Theo Gottwald; 18 Aug 2011, 02:59 AM.

          Comment

          Working...
          X