mirror of
https://gitlab.rlp.net/mobitar/julia_course.git
synced 2024-11-16 13:28:10 +00:00
Improve performance demo
This commit is contained in:
parent
d2a4b883ee
commit
826b6931d3
3 changed files with 13 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
### A Pluto.jl notebook ###
|
### A Pluto.jl notebook ###
|
||||||
# v0.18.4
|
# v0.19.0
|
||||||
|
|
||||||
using Markdown
|
using Markdown
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
### A Pluto.jl notebook ###
|
### A Pluto.jl notebook ###
|
||||||
# v0.18.4
|
# v0.19.0
|
||||||
|
|
||||||
using Markdown
|
using Markdown
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
### A Pluto.jl notebook ###
|
### A Pluto.jl notebook ###
|
||||||
# v0.18.4
|
# v0.19.0
|
||||||
|
|
||||||
using Markdown
|
using Markdown
|
||||||
using InteractiveUtils
|
using InteractiveUtils
|
||||||
|
@ -410,7 +410,7 @@ md"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ╔═╡ 6509dddd-ff17-49db-8e5e-fcea1ef0026c
|
# ╔═╡ 6509dddd-ff17-49db-8e5e-fcea1ef0026c
|
||||||
N3 = 1000000
|
N3 = 500000
|
||||||
|
|
||||||
# ╔═╡ 2a24aebc-0654-4d00-bdab-627a8e1a75f2
|
# ╔═╡ 2a24aebc-0654-4d00-bdab-627a8e1a75f2
|
||||||
# Bad usage of a global array of type Any (container with abstract type)
|
# Bad usage of a global array of type Any (container with abstract type)
|
||||||
|
@ -418,6 +418,9 @@ begin
|
||||||
sin_vals = []
|
sin_vals = []
|
||||||
|
|
||||||
function global_allocating_access(N)
|
function global_allocating_access(N)
|
||||||
|
# First, empty the array because @btime runs the function multiple times
|
||||||
|
empty!(sin_vals)
|
||||||
|
|
||||||
for i in 1:N
|
for i in 1:N
|
||||||
push!(sin_vals, sin(i))
|
push!(sin_vals, sin(i))
|
||||||
end
|
end
|
||||||
|
@ -434,6 +437,9 @@ begin
|
||||||
typed_sin_vals = Float64[]
|
typed_sin_vals = Float64[]
|
||||||
|
|
||||||
function typed_global_allocating_access(N)
|
function typed_global_allocating_access(N)
|
||||||
|
# First, empty the array because @btime runs the function multiple times
|
||||||
|
empty!(typed_sin_vals)
|
||||||
|
|
||||||
for i in 1:N
|
for i in 1:N
|
||||||
push!(typed_sin_vals, sin(i))
|
push!(typed_sin_vals, sin(i))
|
||||||
end
|
end
|
||||||
|
@ -483,6 +489,9 @@ begin
|
||||||
passed_sin_vals = Float64[]
|
passed_sin_vals = Float64[]
|
||||||
|
|
||||||
function local_access(N, sin_vals)
|
function local_access(N, sin_vals)
|
||||||
|
# First, empty the array because @btime runs the function multiple times
|
||||||
|
empty!(passed_sin_vals)
|
||||||
|
|
||||||
for i in 1:N
|
for i in 1:N
|
||||||
push!(sin_vals, sin(i))
|
push!(sin_vals, sin(i))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue