Open albinahlback opened 3 years ago
Thanks for this. I presume you have seen #13 to check the history of this code?
Can you provide some screenshots with the new algorithm for different sizes of circles, as well as some timings for the old and new code?
I added the testfile in test/
. Here's the result, which clearly proves that this way is faster:
# Starting julia
julia> include("circleperformance.jl")
testnew (generic function with 1 method)
# Running every test, so everything gets compiled before timing
julia> ren = myinit()
Ptr{SimpleDirectMediaLayer.Renderer} @0x0000000004768490
julia> @time testold(ren, circles, 1000, false)
1.325373 seconds
julia> ren = myinit()
Ptr{SimpleDirectMediaLayer.Renderer} @0x0000000004bfd2d0
julia> @time testold(ren, circles, 1000, true)
2.234989 seconds
julia> ren = myinit()
Ptr{SimpleDirectMediaLayer.Renderer} @0x000000006cdce890
julia> @time testnew(ren, circles, 1000, false)
0.898482 seconds (40.00 k allocations: 3.662 MiB)
julia> ren = myinit()
Ptr{SimpleDirectMediaLayer.Renderer} @0x000000006cd6e8a0
julia> @time testnew(ren, circles, 1000, true)
0.596087 seconds (40.00 k allocations: 3.662 MiB)
The first sequence of circles on the left have the radius 1 to 7. The ones to the right have the radius 49 to 81.
As you can see, the smaller ones have a somewhat odd shape. But in my opinion, this is fine when considering that the code is smaller and faster.
By usage of trigonometric function, I was able to reduce the computational complexity of the algorithm from O(r^2) to O(r). Further note the lack of
if
statements within thefor
loops.Note that some smaller circles (r ~= 2), the appearance is somewhat wierd. Maybe someone can see if one should use
ceil
orfloor
instead ofround
. However, I think this is worth the performance gain.Resolves #7