From e2e2038626be894feeec2796d26e644cbf081790 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Thu, 20 Jul 2023 14:22:17 +0000 Subject: [PATCH 1/2] Add more benchmarks --- benches/multithreaded/bigint/Project.toml | 1 + benches/multithreaded/bigint/pollardt.jl | 44 +++++++++++++++++++ .../multithreaded/small_arrays/Project.toml | 1 + .../multithreaded/small_arrays/alloc_alot.jl | 14 ++++++ 4 files changed, 60 insertions(+) create mode 100644 benches/multithreaded/bigint/Project.toml create mode 100644 benches/multithreaded/bigint/pollardt.jl create mode 100644 benches/multithreaded/small_arrays/Project.toml create mode 100644 benches/multithreaded/small_arrays/alloc_alot.jl diff --git a/benches/multithreaded/bigint/Project.toml b/benches/multithreaded/bigint/Project.toml new file mode 100644 index 0000000..81648c0 --- /dev/null +++ b/benches/multithreaded/bigint/Project.toml @@ -0,0 +1 @@ +[deps] diff --git a/benches/multithreaded/bigint/pollardt.jl b/benches/multithreaded/bigint/pollardt.jl new file mode 100644 index 0000000..988968c --- /dev/null +++ b/benches/multithreaded/bigint/pollardt.jl @@ -0,0 +1,44 @@ +include(joinpath("..", "..", "..", "utils.jl")) + +function pollardfactor(n::T=big(1208925819691594988651321)) where T<:Integer + for c in T(1):(n - 3) + G, r, q = ones(T,3) + y = 2 + m::T = 1900 + ys::T = 0 + x::T = 0 + while G == 1 + x = y + for i in 1:r + y = (y^2 + c) % n + end + k = T(0) + G = T(1) + while k < r && G == 1 + for i in 1:min(r - k, m) + ys = y + y = (y^2 + c) % n + q = (q * abs(x - y)) % n + end + G = gcd(q, n) + k += m + end + r *= 2 + end + G == n && (G = T(1)) + while G == 1 + ys = (ys^2 + c) % n + G = gcd(abs(x - ys), n) + end + if G != n + return G + end + end +end + +function threadfun() + Threads.@threads for i in 1:8 + pollardfactor() + end +end +@gctime threadfun() diff --git a/benches/multithreaded/small_arrays/Project.toml b/benches/multithreaded/small_arrays/Project.toml new file mode 100644 index 0000000..81648c0 --- /dev/null +++ b/benches/multithreaded/small_arrays/Project.toml @@ -0,0 +1 @@ +[deps] diff --git a/benches/multithreaded/small_arrays/alloc_alot.jl b/benches/multithreaded/small_arrays/alloc_alot.jl new file mode 100644 index 0000000..eb5f15f --- /dev/null +++ b/benches/multithreaded/small_arrays/alloc_alot.jl @@ -0,0 +1,14 @@ +include(joinpath("..", "..", "..", "utils.jl")) + +const N = 2500 +a = Vector{Vector{Float64}}(undef,N) + +function alloc_alot() + for j in 1:1000 + Threads.@threads for i in 1:N + a[i] = rand(2500) + end + end + end + +@gctime alloc_alot() From 89350930356d8b978622151cc025313a6d4e3795 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Thu, 20 Jul 2023 16:11:08 +0000 Subject: [PATCH 2/2] Formatting + readme changes --- README.md | 5 ++++- benches/multithreaded/bigint/pollardt.jl | 6 +++--- benches/multithreaded/small_arrays/alloc_alot.jl | 14 +++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 887bc23..eb0b6f9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ There are three classes of benchmarks: | | | tree.jl | Small pointer-heavy data structure. | | | strings | strings.jl | | | Multithreaded | binary_tree | tree_immutable.jl | Small pointer-heavy data structure. | -| | | tree_mutable.jl | Small pointer-heavy data structure. | +| | | tree_mutable.jl | Small pointer-heavy data structure. | +| | bigarrays | objarray.jl | Large arrays with pointer elements | +| | small_array | alloc_alot.jl | Lots of malloc backed arrays | +| | bigint | pollardt.jl | Tests small `BigInt`s but threaded. | | Slow | rb\_tree | rb\_tree.jl | Pointer graph whose minimum linear arrangement has cost Θ(n²). | | | pidigits.jl | Tests large `BigInt`s. | diff --git a/benches/multithreaded/bigint/pollardt.jl b/benches/multithreaded/bigint/pollardt.jl index 988968c..f9e3998 100644 --- a/benches/multithreaded/bigint/pollardt.jl +++ b/benches/multithreaded/bigint/pollardt.jl @@ -1,8 +1,8 @@ include(joinpath("..", "..", "..", "utils.jl")) -function pollardfactor(n::T=big(1208925819691594988651321)) where T<:Integer - for c in T(1):(n - 3) - G, r, q = ones(T,3) +function pollardfactor(n::T=big(1208925819691594988651321)) where {T<:Integer} + for c in T(1):(n-3) + G, r, q = ones(T, 3) y = 2 m::T = 1900 ys::T = 0 diff --git a/benches/multithreaded/small_arrays/alloc_alot.jl b/benches/multithreaded/small_arrays/alloc_alot.jl index eb5f15f..c5b22c1 100644 --- a/benches/multithreaded/small_arrays/alloc_alot.jl +++ b/benches/multithreaded/small_arrays/alloc_alot.jl @@ -1,14 +1,14 @@ include(joinpath("..", "..", "..", "utils.jl")) const N = 2500 -a = Vector{Vector{Float64}}(undef,N) +a = Vector{Vector{Float64}}(undef, N) function alloc_alot() - for j in 1:1000 - Threads.@threads for i in 1:N - a[i] = rand(2500) - end - end - end + for j in 1:1000 + Threads.@threads for i in 1:N + a[i] = rand(2500) + end + end +end @gctime alloc_alot()