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!
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
NinjaTrader
Empty lines and performance?
Collapse
X
-
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
-
Originally posted by elliot5 View PostDoes 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.
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.
- Likes 2
Comment
-
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.
Good luck with the programming, and many profitable trades for you.
- Likes 2
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
1 view
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
6 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
10 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
||
Started by alifarahani, Today, 09:40 AM
|
6 responses
41 views
0 likes
|
Last Post
by alifarahani
Today, 03:18 PM
|
Comment