Skip to content

Commit

Permalink
add Triangle, Bitmap, Image to benchmark.jl and update it's Manifest.…
Browse files Browse the repository at this point in the history
…toml (#169)

* update Manifest.toml to benchmark my local SimpleDraw module

* add Triangle to benchmark.jl

* update order of shapes in benchmark.jl

* add Bitmap to benchmark.jl

* add Image to benchmark.jl

* pin SimpleDraw version to a latest commit for benchmarking
  • Loading branch information
Sid-Bhatia-0 authored Jan 11, 2023
1 parent 39515c1 commit da0aae4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
26 changes: 19 additions & 7 deletions benchmark/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.2"
julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "376d8ee8553d54ddecabbda188a72303f346d537"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[deps.BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
git-tree-sha1 = "4c10eee4af024676200bc7752e536f858c6b8f93"
git-tree-sha1 = "d9a9701b899b30332bbcb3e1679c41cce81fb0e8"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.3.1"
version = "1.3.2"

[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.1+0"

[[deps.Dates]]
deps = ["Printf"]
Expand Down Expand Up @@ -42,12 +44,13 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.20+0"

[[deps.Parsers]]
deps = ["Dates"]
git-tree-sha1 = "3b429f37de37f1fc603cc1de4a799dc7fbe4c0b6"
deps = ["Dates", "SnoopPrecompile"]
git-tree-sha1 = "6466e524967496866901a78fca3f2e9ea445a559"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.3.0"
version = "2.5.2"

[[deps.Printf]]
deps = ["Unicode"]
Expand All @@ -63,15 +66,23 @@ uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.SimpleDraw]]
git-tree-sha1 = "0fe04590acbc1a3de2c0556a946d04e20c9f4c2a"
git-tree-sha1 = "9207a3da2bf4f3c14d116d3849043b2d583cae67"
repo-rev = "39515c19759cca39ba590924b4c739854525cc4b"
repo-url = "https://github.com/Sid-Bhatia-0/SimpleDraw.jl.git"
uuid = "d1acf6f4-8553-480e-80ae-3c883f0a995a"
version = "0.4.0"

[[deps.SnoopPrecompile]]
git-tree-sha1 = "f604441450a3c0569830946e5b33b78c928e1a85"
uuid = "66db9d55-30c0-4569-8b51-7e840670fc0c"
version = "1.0.1"

[[deps.SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -90,3 +101,4 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "5.1.1+0"
57 changes: 46 additions & 11 deletions benchmark/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,65 @@ import Dates
import SimpleDraw as SD

const SHAPE_TYPES = [
SD.Point,
SD.Background,
SD.Point,
SD.Line,
SD.ThickLine,
SD.Circle,
SD.FilledCircle,
SD.ThickCircle,
SD.Triangle,
SD.FilledTriangle,
SD.Rectangle,
SD.FilledRectangle,
SD.ThickRectangle,
SD.FilledTriangle,
SD.Circle,
SD.FilledCircle,
SD.ThickCircle,
SD.Bitmap,
SD.Image,
SD.Character,
SD.TextLine,
]

const SIZES = [64, 256, 1024]

get_shape(::Type{SD.Point}, n) = SD.Point(n ÷ 2 + 1, n ÷ 2 + 1)
get_shape(::Type{SD.Background}, n) = SD.Background()
get_shape(::Type{SD.Point}, n) = SD.Point(n ÷ 2 + 1, n ÷ 2 + 1)
get_shape(::Type{SD.Line}, n) = SD.Line(SD.Point(n ÷ 8 + 1, 2), SD.Point((7 * n) ÷ 8, n - 1))
get_shape(::Type{SD.ThickLine}, n) = SD.ThickLine(SD.Point(n ÷ 8 + 1, n ÷ 8 + 1), SD.Point((7 * n) ÷ 8, (7 * n) ÷ 8), (n ÷ 8) - 1)
get_shape(::Type{SD.Circle}, n) = SD.Circle(SD.Point(2, 2), n - 2)
get_shape(::Type{SD.FilledCircle}, n) = SD.FilledCircle(SD.Point(2, 2), n - 2)
get_shape(::Type{SD.ThickCircle}, n) = SD.ThickCircle(SD.Point(2, 2), n - 2, n ÷ 4)
get_shape(::Type{SD.Triangle}, n) = SD.Triangle(SD.Point(2, 2), SD.Point(n - 1, n ÷ 2), SD.Point(n ÷ 2, n -1))
get_shape(::Type{SD.FilledTriangle}, n) = SD.FilledTriangle(SD.Point(2, 2), SD.Point(n - 1, n ÷ 2), SD.Point(n ÷ 2, n -1))
get_shape(::Type{SD.Rectangle}, n) = SD.Rectangle(SD.Point(2, 2), n - 1, n - 1)
get_shape(::Type{SD.FilledRectangle}, n) = SD.FilledRectangle(SD.Point(2, 2), n - 1, n - 1)
get_shape(::Type{SD.FilledTriangle}, n) = SD.FilledTriangle(SD.Point(2, 2), SD.Point(n - 1, n ÷ 2), SD.Point(n ÷ 2, n -1))
get_shape(::Type{SD.ThickRectangle}, n) = SD.ThickRectangle(SD.Point(2, 2), n - 1, n - 1, n ÷ 4)
get_shape(::Type{SD.Circle}, n) = SD.Circle(SD.Point(2, 2), n - 2)
get_shape(::Type{SD.FilledCircle}, n) = SD.FilledCircle(SD.Point(2, 2), n - 2)
get_shape(::Type{SD.ThickCircle}, n) = SD.ThickCircle(SD.Point(2, 2), n - 2, n ÷ 4)

function get_shape(::Type{SD.Bitmap}, n)
position = SD.Point(2, 2)
bitmap = falses(n - 2, n - 2)
for j in 1:size(bitmap, 2)
for i in 1:size(bitmap, 1)
bitmap[i, j] = iseven(i + j)
end
end

return SD.Bitmap(position, bitmap)
end

function get_shape(::Type{SD.Image}, n, color_type)
position = SD.Point(2, 2)
image2 = zeros(color_type, n - 2, n - 2)
for j in 1:size(image2, 2)
for i in 1:size(image2, 1)
if iseven(i + j)
image2[i, j] = one(color_type)
end
end
end

return SD.Image(position, image2)
end

get_shape(::Type{SD.Character}, n) = SD.Character(SD.Point(2, 2), 'A', SD.TERMINUS_32_16)

function get_shape(::Type{SD.TextLine}, n)
Expand All @@ -50,7 +81,11 @@ function get_benchmarks(shape_types, sizes)
image = zeros(typeof(color), n, n)
for ShapeType in shape_types
shape_name = nameof(ShapeType)
shape = get_shape(ShapeType, n)
if ShapeType == SD.Image
shape = get_shape(ShapeType, n, typeof(color))
else
shape = get_shape(ShapeType, n)
end
benchmark = BT.@benchmark SD.draw!($(Ref(image))[], $(Ref(shape))[], $(Ref(color))[])
memory, median_time = get_summary(benchmark)
benchmarks[(shape_name, n)] = (shape, memory, median_time)
Expand Down

0 comments on commit da0aae4

Please sign in to comment.