Book Image

Mastering Julia

Book Image

Mastering Julia

Overview of this book

Table of Contents (17 chapters)
Mastering Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Performance tips


Julia is quick, but poor coding can slow it down markedly. If you are developing enterprise software and/or distributing on GitHub, you need to pay more attention to some of the features and nuances of the language.

The online manual has a long section on performance tips, including a useful style guide and a section of frequently asked questions, which will prove to be illuminating. I've cherry-picked a few that I found of interest.

Best practice

First, a few points about variables, arrays, and types:

  • Global variables: These may change at different points, so it is hard for the compiler to optimize the code. Wherever possible, variables should be locally defined or passed to functions as arguments. If a variable is actually being used to store a value that does not change, this should be declared as const.

  • Changing a variable type: If you are accumulating a sum of floating point numbers, be careful to initialize the starting point for total as 0.0 and not 0, as the latter...