You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/lectures/lecture_06/lab.md
+24-18Lines changed: 24 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,17 +124,19 @@ In some cases the compiler uses loop unrolling[^1] optimization to speed up loop
124
124
nothing #hide
125
125
```
126
126
127
-
```@ansi lab06_intro
128
-
@code_llvm debuginfo=:none polynomial(a,x)
129
-
@code_llvm debuginfo=:none polynomial(ac,x)
130
-
```
131
-
132
127
More than 2x speedup
133
-
```@ansi lab06_intro
128
+
```@repl lab06_intro
134
129
@btime polynomial($a,$x)
135
130
@btime polynomial($ac,$x)
136
131
```
137
132
133
+
```@ansi lab06_intro
134
+
@code_llvm debuginfo=:none polynomial(a,x)
135
+
@code_llvm debuginfo=:none polynomial(ac,x)
136
+
```
137
+
138
+
139
+
138
140
### Recursion inlining depth
139
141
Inlining[^2] is another compiler optimization that allows us to speed up the code by avoiding function calls. Where applicable compiler can replace `f(args)` directly with the function body of `f`, thus removing the need to modify stack to transfer the control flow to a different place. This is yet another optimization that may improve speed at the expense of binary size.
140
142
@@ -201,9 +203,9 @@ Inlining[^2] is another compiler optimization that allows us to speed up the cod
201
203
nothing #hide
202
204
```
203
205
204
-
```@ansi lab06_intro
205
-
@code_typed debuginfo=:none polynomial(a,x)
206
-
```
206
+
```@ansi lab06_intro
207
+
@code_typed debuginfo=:none polynomial(a,x)
208
+
```
207
209
208
210
209
211
## AST manipulation: The first steps to metaprogramming
@@ -290,7 +292,7 @@ Following up on the more general substitution of variables in an expression from
290
292
nothing #hide
291
293
```
292
294
Given a function `replace_i`, which replaces variables `i` for `k` in an expression like the following
293
-
```@ansi lab06_meta
295
+
```@repl lab06_meta
294
296
ex = :(i + i*i + y*i - sin(z))
295
297
@test replace_i(ex) == :(k + k*k + y*k - sin(z))
296
298
```
@@ -305,16 +307,20 @@ Following up on the more general substitution of variables in an expression from
does not work in this simple case, because it will replace "i" inside the `sin(z)` expression. We can play with regular expressions to obtain something, that is more robust
does not work in this simple case, because it will replace "i" inside the `sin(z)` expression. We can play with regular expressions to obtain something, that is more robust
however the code may now be harder to read. Thus it is preferable to use the parsed AST when manipulating Julia's code.
318
324
319
325
If the exercises so far did not feel very useful let's focus on one, that is similar to a part of the [`IntervalArithmetics.jl`](https://github.com/JuliaIntervals/IntervalArithmetic.jl) pkg.
0 commit comments