From 65b2d85b8e62d3390d9bf1bb741f12e57d254ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 3 Mar 2023 19:25:23 +0100 Subject: [PATCH] Add errata entry --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index a8998a4..a9a2469 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,55 @@ Kamiński, Bogumił. 2023. *Julia for Data Analysis*. Manning. ## Errata + +### Chapter 1, section 1.2.1, page 7 + +I show the following example of code execution: + +``` +julia> function sum_n(n) + s = 0 + for i in 1:n + s += i + end + return s + end +sum_n (generic function with 1 method) + +julia> @time sum_n(1_000_000_000) + 0.000001 seconds +500000000500000000 +``` + +This timining is very fast (and the reason is explained in the book). +The issue is that this is the situation under Julia 1.7. + +Under Julia 1.8 and Julia 1.9 running the same code takes longer (tested under Julia 1.9-beta4): + +``` +julia> @time sum_n(1_000_000_000) + 2.265569 seconds +500000000500000000 +``` + +The reason for this inconsistency is a bug in `@time` macro introduced in Julia 1.8 release. +The `sum_n(1_000_000_000)` call (without `@time`) is executed fast. +Here is a simplified benchmark (run under Julia 1.9-beta4): + +``` +julia> let + start = time_ns() + v = sum_n(1_000_000_000) + stop=time_ns() + v, Int(stop - start) + end +(500000000500000000, 1000) +``` + +Unfortunately there is an issue with the `@time` +macro used in global scope, that needs to be resolved in Base Julia. +See [this issue](https://github.com/JuliaLang/julia/issues/47561). + ### Chapter 2, section 2.3.1, page 30 I compare the following expressions: