Skip to content

Commit b618b57

Browse files
committed
Add various benchmarks
1 parent d7f7df1 commit b618b57

File tree

9 files changed

+240
-4
lines changed

9 files changed

+240
-4
lines changed

benchmark/autofill.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function coarse_and_fine_autofill()
2+
cs = CoordinateSystem("autofill_bench", nm)
3+
pa = Path(nm)
4+
pa.metadata = SemanticMeta(:metal_negative)
5+
bspline!(pa, [Point(1000μm, 1000μm)], 90°, Paths.SimpleCPW(10μm, 6μm))
6+
meander!(pa, 6000μm, 500μm, 200μm, -180°)
7+
bspline!(pa, [Point(4000μm, 0μm)], 0°)
8+
addref!(cs, pa)
9+
addref!(cs, pa, Point(-500μm, 0μm), rot=90°)
10+
11+
coarse_grid_x = (-3000:250:5000)μm
12+
coarse_grid_y = (-1000:250:5000)μm
13+
fine_grid_x = (-3000:25:5000)μm
14+
fine_grid_y = (-1000:25:5000)μm
15+
16+
coarse_dummy = CoordinateSystem("coarse", nm)
17+
place!(coarse_dummy, centered(Rounded(Rectangle(100μm, 100μm), 50μm)), :metal_negative)
18+
fine_dummy = CoordinateSystem("fine", nm)
19+
place!(fine_dummy, centered(Rounded(Rectangle(10μm, 10μm), 5μm)), :metal_negative)
20+
21+
autofill!(cs, coarse_dummy, coarse_grid_x, coarse_grid_y, make_halo(150μm))
22+
return autofill!(cs, fine_dummy, fine_grid_x, fine_grid_y, make_halo(50μm))
23+
end
24+
25+
SUITE["autofill"] = @benchmarkable coarse_and_fine_autofill()

benchmark/benchmarks.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
using Test, BenchmarkTools
2-
const SUITE = BenchmarkGroup()
3-
42
using DeviceLayout, Pkg, FileIO, Unitful, DeviceLayout.PreferredUnits
3+
using DeviceLayout.SchematicDrivenLayout
4+
import Random: default_rng, rand, seed!
5+
56
const um = μm
7+
const SUITE = BenchmarkGroup()
68

7-
include(joinpath(@__DIR__, "clipping.jl"))
9+
include("autofill.jl")
10+
include("bounds.jl")
11+
include("clipping.jl")
12+
include("curves.jl")
13+
include("intersect.jl")
14+
include("polygons.jl")
15+
include("schematic.jl")

benchmark/bounds.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
SUITE["bounds"] = BenchmarkGroup()
2+
SUITE["flatten"] = BenchmarkGroup()
3+
4+
rng = seed!(default_rng(), 111)
5+
6+
num_rects = 1_000
7+
p1s = reinterpret(Point{Int}, rand(Int, 2, num_rects))
8+
p2s = reinterpret(Point{Int}, rand(Int, 2, num_rects))
9+
random_rectangles = [Rectangle(p1, p2) for (p1, p2) in zip(p1s, p2s)]
10+
random_circles = [circle_polygon(1.0, 10°) for p1 in p1s]
11+
12+
c_shallow = Cell{Float64}("shallow")
13+
c_circ = Cell{Float64}("circle")
14+
render!(c_circ, circle_polygon(10.0, 10°))
15+
rots = rand(num_rects) * 2π
16+
for (p1, rot) in zip(p1s, rots)
17+
addref!(c_shallow, c_circ, p1, rot=rot)
18+
end
19+
20+
c_nested = Cell{Float64}("nested")
21+
rots = rand(num_rects) * 2π
22+
nextcell = c_nested
23+
for (p1, rot) in zip(p1s, rots)
24+
global nextcell
25+
c = Cell{Float64}(uniquename("nested"))
26+
addref!(nextcell, c, p1, rot=rot)
27+
nextcell = c
28+
render!(nextcell, circle_polygon(10.0, 10°))
29+
end
30+
31+
c_arrayed = Cell{Float64}("arrayed")
32+
addarr!(
33+
c_arrayed,
34+
c_circ,
35+
numrows=31,
36+
numcols=31,
37+
deltarow=Point(0.0, 10.0),
38+
deltacol=Point(10.0, 0.0)
39+
)
40+
41+
SUITE["bounds"]["random_rectangles"] = @benchmarkable bounds($random_rectangles)
42+
SUITE["bounds"]["random_circles"] = @benchmarkable bounds($random_circles)
43+
SUITE["bounds"]["shallow_references"] = @benchmarkable bounds($c_shallow)
44+
SUITE["bounds"]["nested_references"] = @benchmarkable bounds($c_nested)
45+
46+
SUITE["flatten"]["shallow_references"] = @benchmarkable flatten($c_shallow)
47+
SUITE["flatten"]["nested_references"] = @benchmarkable flatten($c_nested)
48+
SUITE["flatten"]["array_reference"] = @benchmarkable flatten($c_arrayed)

benchmark/clipping.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ c = element_metadata(difference2d_8000_skew)
2727
a = splice!(b, findall(m -> m == GDSMeta(0, 0), c))
2828

2929
SUITE["clipping"]["difference2d"]["8000_skew"] = @benchmarkable difference2d($(a), $(b))
30+
31+
function offset_difference()
32+
c = Cell{Float64}("test")
33+
poly = circle_polygon(1.5, 60°)
34+
render!(c, poly)
35+
ref = aref(c, Point(-3.0, 5.0), nc=4, deltacol=Point(2.0, 0.0))
36+
els = [poly; elements(flatten(ref))]
37+
off = offset(els, 0.2)
38+
boo = difference2d(off, els)
39+
return render!(c, boo, GDSMeta(1)) # Render to force interiorcuts
40+
end
41+
42+
SUITE["clipping"]["difference2d_offset"] = @benchmarkable offset_difference()

benchmark/curves.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
SUITE["curves"] = BenchmarkGroup()
2+
3+
function turns()
4+
c = Cell{Float64}("test")
5+
turn_path = Path{Float64}()
6+
for i = 1:10
7+
turn!(turn_path, 45°, 20.0 * i, Paths.CPW(10.0, 6.0))
8+
turn!(turn_path, -45°, 20.0 * i)
9+
end
10+
return render!(c, turn_path, GDSMeta())
11+
end
12+
13+
function bsplines()
14+
c = Cell{Float64}("test")
15+
bspline_path = Path{Float64}()
16+
for i = 1:10
17+
bspline!(
18+
bspline_path,
19+
[p0(bspline_path) + Point(20 * i, 10 * i)],
20+
0°,
21+
Paths.CPW(10.0, 6.0),
22+
endpoints_speed=20.0 * i
23+
)
24+
end
25+
return render!(c, bspline_path, GDSMeta())
26+
end
27+
28+
function offset_bspline_approx()
29+
bspline_path = Path{Float64}()
30+
for i = 1:10
31+
bspline!(
32+
bspline_path,
33+
[p0(bspline_path) + Point(20 * i, 10 * i^2)],
34+
0°,
35+
Paths.CPW(10.0, 6.0),
36+
endpoints_speed=20.0 * i
37+
)
38+
Paths.bspline_approximation(Paths.offset(bspline_path[end].seg, 11.0))
39+
end
40+
end
41+
42+
SUITE["curves"]["turns_render"] = @benchmarkable turns()
43+
SUITE["curves"]["bsplines_render"] = @benchmarkable bsplines()
44+
SUITE["curves"]["offset_bspline_approximation"] = @benchmarkable offset_bspline_approx()

benchmark/intersect.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
paths_vert = [Path(i * 0.1mm, (-1)^(i + 1) * (1mm), α0=(-1)^i * π / 2) for i = -5:5]
2+
paths_horiz = [Path((-1)^(i) * (1mm), i * 0.1mm, α0=(-1)^i * π / 2 + π / 2) for i = -5:5]
3+
4+
sty = Paths.SimpleCPW(10μm, 6μm)
5+
straight!.(paths_vert, 2mm, Ref(sty))
6+
straight!.(paths_horiz, 2mm, Ref(sty))
7+
all_paths = vcat(paths_vert, paths_horiz)
8+
9+
SUITE["intersection"] = BenchmarkGroup()
10+
SUITE["intersection"]["straight_lines"] =
11+
@benchmarkable Intersect.prepared_intersections($all_paths)

benchmark/polygons.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
SUITE["polygons"] = BenchmarkGroup()
2+
SUITE["polygons"]["circles"] = BenchmarkGroup()
3+
SUITE["polygons"]["rectangles"] = BenchmarkGroup()
4+
5+
function rectangles(n; output_dir=nothing)
6+
c = Cell{Float64}("rectangles")
7+
for i = 1:n
8+
render!(c, Rectangle(Point(i, 0.0), Point(i + 1, 1.0)))
9+
end
10+
return !isnothing(output_dir) && save(joinpath(output_dir, "$(n)_rectangles.gds"), c)
11+
end
12+
13+
function rectangles_units(n, unit; output_dir=nothing)
14+
um = uconvert(unit, DeviceLayout.onemicron(1unit))
15+
c = Cell{typeof(1.0nm)}("rectangles") # coordinatetype(c) may or may not be same as unit
16+
for i = 1:n
17+
render!(c, Rectangle(Point(i * um, 0 * um), Point((i + 1) * um, 1 * um)))
18+
end
19+
return !isnothing(output_dir) &&
20+
save(joinpath(output_dir, "$(n)_rectangles_units.gds"), c)
21+
end
22+
23+
function circles_direct(n; output_dir=nothing)
24+
c = Cell{Float64}("circles")
25+
for i = 1:n
26+
render!(c, Point(i, 0.0) + circle_polygon(1, 2π / 8000))
27+
end
28+
return !isnothing(output_dir) && save(joinpath(output_dir, "$(n)_circles.gds"), c)
29+
end
30+
31+
function circles_direct_units(n, unit; output_dir=nothing)
32+
um = uconvert(unit, DeviceLayout.onemicron(1unit))
33+
c = Cell{typeof(1.0nm)}("circles") # coordinatetype(c) may or may not be same as unit
34+
for i = 1:n
35+
render!(c, Point(i * um, 0.0 * um) + circle_polygon(1 * um, 2π / 8000))
36+
end
37+
return !isnothing(output_dir) && save(joinpath(output_dir, "$(n)_circles_units.gds"), c)
38+
end
39+
40+
function circles_entity_delta(n; output_dir=nothing)
41+
c = Cell{Float64}("circles")
42+
for i = 1:n
43+
render!(c, Circle(Point(i, 0.0), 1.0), Δθ=2π / 8000)
44+
end
45+
return !isnothing(output_dir) && save(joinpath(output_dir, "$(n)_circles_delta.gds"), c)
46+
end
47+
48+
function circles_entity_atol(n; output_dir=nothing)
49+
c = Cell{Float64}("circles")
50+
for i = 1:n
51+
render!(c, Circle(Point(i, 0.0), 1.0), atol=7.714e-8) # 7999 points
52+
end
53+
return !isnothing(output_dir) && save(joinpath(output_dir, "$(n)_circles_atol.gds"), c)
54+
end
55+
56+
dir = mktempdir()
57+
SUITE["polygons"]["rectangles"]["render"] = @benchmarkable rectangles(10_000)
58+
SUITE["polygons"]["rectangles"]["render_gds"] =
59+
@benchmarkable rectangles(10_000, output_dir=$dir)
60+
SUITE["polygons"]["rectangles"]["render_units"] =
61+
@benchmarkable rectangles_units(10_000, $nm)
62+
SUITE["polygons"]["rectangles"]["render_units_gds"] =
63+
@benchmarkable rectangles_units(10_000, $nm, output_dir=$dir)
64+
SUITE["polygons"]["rectangles"]["render_convertunits"] =
65+
@benchmarkable rectangles_units(10_000, $μm)
66+
SUITE["polygons"]["circles"]["direct"] = @benchmarkable circles_direct(1_000)
67+
SUITE["polygons"]["circles"]["direct_gds"] =
68+
@benchmarkable circles_direct(1_000, output_dir=$dir)
69+
SUITE["polygons"]["circles"]["direct_units"] =
70+
@benchmarkable circles_direct_units(1_000, $nm)
71+
SUITE["polygons"]["circles"]["direct_units_gds"] =
72+
@benchmarkable circles_direct_units(1_000, $nm, output_dir=$dir)
73+
SUITE["polygons"]["circles"]["entity_delta"] = @benchmarkable circles_entity_delta(1_000)
74+
SUITE["polygons"]["circles"]["entity_atol"] = @benchmarkable circles_entity_atol(1_000)

benchmark/schematic.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
g = SchematicGraph("test")
2+
lastnode = add_node!(g, Spacer{Float64}(p1=Point(10.0, 10.0)))
3+
for i = 1:100
4+
global lastnode
5+
lastnode = fuse!(
6+
g,
7+
lastnode => :p1_east,
8+
Spacer{Float64}(p1=Point(10.0, 10.0)) => :p0_southwest
9+
)
10+
end
11+
12+
SUITE["schematic"] = BenchmarkGroup()
13+
SUITE["schematic"]["plan"] = @benchmarkable plan($g)

benchmark/tune.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"Julia":"1.6.0-rc2","BenchmarkTools":"0.4.3"},[["BenchmarkGroup",{"data":{"clipping":["BenchmarkGroup",{"data":{"difference2d":["BenchmarkGroup",{"data":{"100_square":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"3600_square":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"961_square":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"19881_square":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"8000_skew":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"10000_square":["BenchmarkTools.Parameters",{"gctrial":true,"time_tolerance":0.05,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}]},"tags":[]}]},"tags":[]}]]]
1+
[{"Julia":"1.12.0","BenchmarkTools":{"major":1,"minor":6,"patch":2,"prerelease":[],"build":[]}},[["BenchmarkGroup",{"data":{"schematic":["BenchmarkGroup",{"data":{"plan":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"curves":["BenchmarkGroup",{"data":{"turns_render":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"bsplines_render":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"offset_bspline_approximation":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"polygons":["BenchmarkGroup",{"data":{"rectangles":["BenchmarkGroup",{"data":{"render_units":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"render":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"render_units_gds":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"render_convertunits":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"render_gds":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"circles":["BenchmarkGroup",{"data":{"direct":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"entity_delta":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"direct_units_gds":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"direct_units":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"entity_atol":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"direct_gds":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}]},"tags":[]}],"flatten":["BenchmarkGroup",{"data":{"shallow_references":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"array_reference":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"nested_references":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"clipping":["BenchmarkGroup",{"data":{"difference2d_offset":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"difference2d":["BenchmarkGroup",{"data":{"100_square":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"3600_square":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"961_square":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"19881_square":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"8000_skew":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"10000_square":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}]},"tags":[]}],"bounds":["BenchmarkGroup",{"data":{"random_rectangles":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"shallow_references":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"random_circles":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"nested_references":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"intersection":["BenchmarkGroup",{"data":{"straight_lines":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}],"autofill":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":[]}]]]

0 commit comments

Comments
 (0)