Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #78 #79

Merged
merged 3 commits into from
Dec 12, 2023
Merged

Conversation

yakir12
Copy link
Contributor

@yakir12 yakir12 commented Dec 8, 2023

This PR drammatically improves on performance for ellipse drawing:

using Revise
using BenchmarkTools
using ImageDraw 
import ColorTypes: RGB, N0f8

img = rand(RGB{N0f8}, 1000, 1000)
c = CirclePointRadius(Point(500, 500), 400)
f() = draw!(img, c)
@benchmark f()

before this PR:

BenchmarkTools.Trial: 1875 samples with 1 evaluation.
 Range (min  max):  2.258 ms    5.262 ms  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     2.499 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   2.600 ms ± 292.306 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

       ▅██▆▂▁                                                  
  ▂▃▄▇▇███████▆▇▅▆▇██▆▅▄▃▃▃▃▃▃▃▂▂▁▂▂▂▂▂▃▃▃▃▃▃▃▂▂▂▂▂▃▃▂▂▂▂▁▁▂▂ ▃
  2.26 ms         Histogram: frequency by time        3.63 ms <

 Memory estimate: 3.66 MiB, allocs estimate: 22.

After this PR:

BenchmarkTools.Trial: 8135 samples with 1 evaluation.
 Range (min  max):  594.081 μs   1.619 ms  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     609.660 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   612.257 μs ± 26.233 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

               █        ▁                                       
  ▂▂▂▂▁▁▂▂▃▃▂▃▃█▄▄▄▇▆▅▅▄█▄▄▄▄▄▃▃▃▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  594 μs          Histogram: frequency by time          643 μs <

 Memory estimate: 0 bytes, allocs estimate: 0.

@yakir12
Copy link
Contributor Author

yakir12 commented Dec 11, 2023

Does anyone have time to review this? The code change is pretty small and the improvement is substantial, to put it in relative terms 😛

src/ellipse2d.jl Outdated
@@ -15,16 +13,14 @@ function draw!(img::AbstractArray{T, 2}, ellipse::Ellipse, color::T) where T<:Co
for j in ellipse.center.x : ellipse.center.x + ellipse.ρx
val = ((i - ellipse.center.y) / ellipse.ρy) ^ 2 + ((j - ellipse.center.x) / ellipse.ρx) ^ 2
if val < 1 && val >= break_point
push!(ys, i)
push!(xs, j)
yi = Int(i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey yakir, please format it correctly, otherwise it looks good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, I was really confused cause it looked fine in vim but off when I printed it out. Apparently some of the spaces here are tabs, which I think is discouraged (precisely for this reason).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks... but I think you used two spaces. The rest of the package uses four.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed it now.

@mkitti
Copy link
Member

mkitti commented Dec 11, 2023

Looks good to me. The indenting looks a bit strange from my phone though.

@yakir12
Copy link
Contributor Author

yakir12 commented Dec 11, 2023

This file contained tab-spaces so I replaced them with (2) spaces, hope that doesn't go against the style guide of ImageDraw...

@ashwanirathee ashwanirathee merged commit 79008c3 into JuliaImages:master Dec 12, 2023
1 check passed
@yakir12 yakir12 deleted the yg/avoid-building-indices branch December 12, 2023 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants