Which is the fastest statement to run...
technique
Member Posts: 21
We all write code like this all the time so I'm looking for THE definitive answer in terms of performance.
In NAV2017+ which is the fastest statement:
1)
IF GLSetup.GET THEN
IF GLSetup.Fieldname THEN
DoSomething := TRUE;
or
2)
IF (GLSetup.GET) AND (GLSetup.Fieldname) THEN
DoSomething := TRUE;
The 2nd one is my preference and I think it is neater but want the one that executes fastest...
In NAV2017+ which is the fastest statement:
1)
IF GLSetup.GET THEN
IF GLSetup.Fieldname THEN
DoSomething := TRUE;
or
2)
IF (GLSetup.GET) AND (GLSetup.Fieldname) THEN
DoSomething := TRUE;
The 2nd one is my preference and I think it is neater but want the one that executes fastest...
0
Best Answer
-
The first one will be a tiny bit faster, as in the first case second instruction is only executed if the first GET returns true, and in the second case both GET and test on GLSetup.Fieldname are always executed.
The second check IF GLSetup.Fieldname is much much much quicker that the first, to the point that the difference between 1st and 2nd might be unmeasurable.
If you prefer the 2nd form you might get caught some day if the 2nd check is also slow.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
No guesswork needed. Set both of the code snippets into a loop and count the time for x loops. I would bet the difference is negligible in any scenario since there is no real difference in what is done nor in what order it is done. It might very well be that the compiler produces the same code for both examples.
I would care for that if we would code in assembler and counting CPU cycles, but we have to worry more about what is going on on the SQL server side.0 -
The first one will be a tiny bit faster, as in the first case second instruction is only executed if the first GET returns true, and in the second case both GET and test on GLSetup.Fieldname are always executed.
The second check IF GLSetup.Fieldname is much much much quicker that the first, to the point that the difference between 1st and 2nd might be unmeasurable.
If you prefer the 2nd form you might get caught some day if the 2nd check is also slow.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 333 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
