Which conditional expression is faster?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is faster
    IF A+B+C=0
    The generated ASM
    Code:
    ADD?BBW	_A, _B, T1
    ADD?WBW	T1, _C, T1
    CMPNE?WCL	T1, 000h, L00001
    This
    IF A=0 AND B=0 AND C=0 THEN
    Generates
    Code:
    CMPEQ?BCB	_A, 000h, T1
    CMPEQ?BCB	_B, 000h, T2
    LAND?BBW	T1, T2, T2
    CMPEQ?BCB	_C, 000h, T3
    LAND?WBW	T2, T3, T3
    CMPF?WL	T3, L00003
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You will have problem with the first one one day or another (put some values in and figure a roll-over), but the second one is bullet proof.

    If you want to measure it, you may use the regular suggestions
    1. Set a pin before, and clear it after the IF-THEN or code block. Measure the delay with a scope or frequency meter
    2. Same as above, but use an internal Timer and output the data over serail port
    3. Use MPLAB stopwatch

    http://www.picbasic.co.uk/forum/show...33&postcount=9 <-- really handy
    http://www.picbasic.co.uk/forum/show...9&postcount=13
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. conditional defines in PBP?
    By rdxbam in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th March 2010, 14:40
  2. Replies: 5
    Last Post: - 28th May 2008, 10:20
  3. interrupt handling faster than if's?
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 27th October 2006, 01:25
  4. OT - Firefox browser - faster performance
    By malc-c in forum Off Topic
    Replies: 2
    Last Post: - 14th August 2006, 10:33
  5. Conditional Compilation
    By milestag in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd March 2006, 20:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts