Shop OBEX P1 Docs P2 Docs Learn Events
Faster Execution — Parallax Forums

Faster Execution

kt88seampkt88seamp Posts: 112
edited 2009-12-03 15:30 in Propeller 1
Is there a way to execute this code faster?

PUB RunProgram | i

repeat

  repeat i from 0 to numberOfCommands - 1

      case functionCodes[i]
        0:
          LightsOff
        1:
          LightsOn
        2:
          SetBrightness(functionData[i])
        3:
          DelayMs(functionData[i])
[/i][/i][/i]



The code executes four methods based upon a case statement. The repeat loop goes through an array list

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-03 04:46
    The Propeller is very fast. Spin statements execute on the order of microseconds. In your case, the execution speed is determined mostly by the various methods (subroutines) that you're calling. You're not going to gain any significant speed by changing what you've shown as opposed to improving the subroutine execution time.
  • BaggersBaggers Posts: 3,019
    edited 2009-12-03 08:53
    How many cogs are you using for your project? are there any spare? if so you ( or someone ) could convert it to PASM.

    How big are the LightsOff, LightsOn, SetBrightness and DelayMs functions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2009-12-03 12:14
    Could you explain a little more, perhaps the overall way you are doing this could be modified to speed things up.

    Graham
  • ericballericball Posts: 774
    edited 2009-12-03 14:09
    One piece you haven't shown is how you get from i to functioncodes. If it is something other than a simple array dereference then there may be some cycles which can be saved there. Also, if the number of cases is large then subdividing it using if/else may yeild some improvement. You should also have an OTHER case - good programming practice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-12-03 15:30
    Another angle: are you driving these lamps directly through an electrical interface, or indirectly through some protocol (say X-10) ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.