Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Empty lines and performance?

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

    Empty lines and performance?

    Does having a large percentage of empty lines or // out code reduce script reading time / performance? I am 17,000 lines deep but could reduce that by compressing the script considerably if it would help performance.

    #2
    Hello elliot5,

    Thanks for your post.

    The only performance improvement would be in the amount of time it takes the compiler to compile the code. Once compiled into machine code there are no commented-out lines or spaces so the run time performance would not change.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by elliot5 View Post
      Does having a large percentage of empty lines or // out code reduce script reading time / performance? I am 17,000 lines deep but could reduce that by compressing the script considerably if it would help performance.
      Never ever worry about blank lines or comments. Period. Full Stop.

      17,000 lines, with a significant portion of them as comments (as you imply),
      is nothing to the compiler. It will run through these lines like a hot knife
      through butter.

      If you think you need speed improvements, consider a faster computer, or
      at least a faster hard drive, or even a RAM disk. I seriously doubt you'd
      ever detect much speed improvement from any compiler by reducing the
      number of comments or blank lines.

      Comment


        #4
        95 % of the lines are working strategy code, but I think it is clear that I need not compress the file to shave milliseconds off the compile time. Thanks very much for your imput.

        Comment


          #5
          Meaningful comments and good layout of the code in the editor are good things. They enhance code maintenance and readability. As others have mentioned, the compiler will not "think twice" about such things. I have more than 100K lines of (I believe) well-documented code and a few extra seconds of compilation time is worth every comment!

          Performance, on the other hand, is a run-time thing we always need to consider when engineering software. Hardware will sometimes be relevant, but often, it is what we have programmed that has the most effect on increasing/decreasing performance.

          Some things to consider include:
          • Understand how different language features and constructs affect performance -- the same functionality can often be achieved using different language elements, sometimes with dramatically different performance outcomes
          • Understand the logic of the function being performed and structure the code to avoid performance-intensive code unless it is necessary to execute it
          • Look for ways to "simplify" code that becomes "cumbersome" after multiple development edits -- refactoring is your friend ... in most cases!
          • Check "loop" code (i.e. for, foreach, while, do, etc) to ensure only as many iterations as needed are performed -- continue and break are useful to shorten such iterative cycles when certain conditions are met
          • Structure data to avoid unnecessary memory usage -- e.g. don't declare sparse arrays unless the functionality requires it
          • Dispose! When finished with something, always use any disposing capabilities in the language for the constructs used. When done with things that do not explicitly dispose, set variables with structure (e.g. arrays) to null to improve garbage collection.
          There are many ways to program efficiently, and many texts and websites that help in learning more about relevant things. After 40 years as a Software Engineer, I still learn things, as it should be.

          Good luck with the programming, and many profitable trades for you.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ghoul, Today, 06:02 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          179 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X