Skip to content

Commit 0344a7b

Browse files
mschauerElOceanografo
authored andcommitted
Make "Write functions, not just scripts" more prominent in the performance tips (JuliaLang#38052)
* Make recommendation " Write functions, not just scripts" more prominent in the performance tips. * Update doc/src/manual/performance-tips.md
1 parent 871da28 commit 0344a7b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/src/manual/performance-tips.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
In the following sections, we briefly go through a few techniques that can help make your Julia
44
code run as fast as possible.
55

6+
## Performance critical code should be inside a function
7+
8+
Any code that is performance critical should be inside a function. Code inside functions tends to run much faster than top level code, due to how Julia's compiler works.
9+
10+
The use of functions is not only important for performance: functions are more reusable and testable, and clarify what steps are being done and what their inputs and outputs are, [Write functions, not just scripts](@ref) is also a recommendation of Julia's Styleguide.
11+
12+
The functions should take arguments, instead of operating directly on global variables, see the next point.
13+
614
## Avoid global variables
715

816
A global variable might have its value, and therefore its type, change at any point. This makes
917
it difficult for the compiler to optimize code using global variables. Variables should be local,
1018
or passed as arguments to functions, whenever possible.
1119

12-
Any code that is performance critical or being benchmarked should be inside a function.
1320

1421
We find that global names are frequently constants, and declaring them as such greatly improves
1522
performance:

0 commit comments

Comments
 (0)