Options

Performance impact using Begin/End statement

navninjanavninja Member Posts: 2
edited 2014-02-19 in NAV Three Tier
Hi,
I was wondering if there is any performance impact when using Begin/End. I have 2 different examples and was wondering if they are really only style differences or if there is an underlying performance hit when using Begin/End when it is not really needed.

Example 1:

IF <condition> THEN
<Do Something>;

vs

IF <condition> THEN BEGIN
<Do Something>;
END;


Example 2

IF Record.FINDSET THEN
REPEAT
<Do Something>;
UNTIL Record.NEXT = 0;

vs

IF Record.FINDSET THEN BEGIN
REPEAT
<Do Something>;
UNTIL Record.NEXT = 0;
END;


Thank you in advance.

Answers

  • Options
    John_NJohn_N Member Posts: 5
    I suspect not. I suspect that code will be optimised before execution
  • Options
    mdPartnerNLmdPartnerNL Member Posts: 802
    I always use begin end structures. Much easier to read, upgrade and copy into other code snippets.

    Can't think of any reason then (lazy) to not use it. :)
  • Options
    krikikriki Member, Moderator Posts: 9,096
    Lets suppose there is a performance impact in executing the code. We would be talking about microseconds.
    If you do some database access, we are talking about milliseconds.

    So 1 millisecond (generally more) for a database access + 10 microseconds (I think I am thinking LARGE!) for the extra processing = 1010 microseconds for everything.
    => I wouldn't care about those 10 microseconds!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    The instructions generated by the compiler are exactly the same independent of BEGIN / END being used or not. Which also means that there is no speed penalty when the code is executed.

    And as Kriki points out database access is where most of the time is spend which makes it a lot more important to write code that is readable than code which executes a couple of milliseconds faster
    This posting is provided "AS IS" with no warranties, and confers no rights.
Sign In or Register to comment.