-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* streaming * wip * refactors * More tests, added materialize * tidy * Update license text with actual license * Bounding box calculatinos * Change example program --------- Co-authored-by: Boris <boris@workfloor.com>
- Loading branch information
1 parent
ed33c22
commit d48d5e0
Showing
50 changed files
with
1,063 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using GdsSharp.Lib; | ||
using GdsSharp.Lib.Builders; | ||
using GdsSharp.Lib.NonTerminals; | ||
using GdsSharp.Lib.NonTerminals.Elements; | ||
|
||
namespace GdsSharp.Benchmarks; | ||
|
||
public class BufferedStreamBenchmark | ||
{ | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var file = new GdsFile | ||
{ | ||
LibraryName = "Test", | ||
PhysicalUnits = 1e-6, | ||
UserUnits = 1, | ||
}; | ||
|
||
var structure = new GdsStructure | ||
{ | ||
Name = "My structure", | ||
}; | ||
|
||
var pb = new PathBuilder(1000f); | ||
for (var i = 0; i < 1000; i++) | ||
{ | ||
pb.Straight(1000, vertices: 10000); | ||
} | ||
|
||
structure.Elements = pb.Build(); | ||
file.Structures = new[] { structure }; | ||
|
||
using var fs = new FileStream("example.gds", FileMode.Create, FileAccess.Write); | ||
file.WriteTo(fs); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void Cleanup() | ||
{ | ||
File.Delete("example.gds"); | ||
} | ||
|
||
private Stream _stream = null!; | ||
|
||
[IterationSetup] | ||
public void IterationSetup() | ||
{ | ||
_stream = new FileStream("example.gds", FileMode.Open, FileAccess.Read); | ||
} | ||
|
||
[IterationCleanup] | ||
public void IterationCleanup() | ||
{ | ||
_stream.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public GdsFile NoBuffer() | ||
{ | ||
var file = GdsFile.From(_stream); | ||
|
||
file.Structures = file.Structures.ToList(); | ||
foreach(var structure in file.Structures) | ||
{ | ||
structure.Elements = structure.Elements.ToList(); | ||
foreach (var element in structure.Elements) | ||
{ | ||
if (element is not {Element: GdsBoundaryElement b}) continue; | ||
|
||
b.Points = b.Points.ToList(); | ||
} | ||
} | ||
|
||
return file; | ||
} | ||
|
||
|
||
[Benchmark] | ||
[Arguments(4*1024)] | ||
[Arguments(32*1024)] | ||
public GdsFile Buffer(int size) | ||
{ | ||
var bufferedStream = new BufferedStream(_stream, size); | ||
|
||
var file = GdsFile.From(bufferedStream); | ||
|
||
file.Structures = file.Structures.ToList(); | ||
foreach(var structure in file.Structures) | ||
{ | ||
structure.Elements = structure.Elements.ToList(); | ||
foreach (var element in structure.Elements) | ||
{ | ||
if (element is not {Element: GdsBoundaryElement b}) continue; | ||
|
||
b.Points = b.Points.ToList(); | ||
} | ||
} | ||
|
||
return file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace GdsSharp.Benchmarks; | ||
|
||
public class FloatToIntBenchmark | ||
{ | ||
private readonly float[] _xs = new float[1000]; | ||
private readonly float[] _ys = new float[1000]; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var random = new Random(); | ||
for (int i = 0; i < _xs.Length; i++) | ||
{ | ||
_xs[i] = (float)random.NextDouble() * 1000; | ||
_ys[i] = (float)random.NextDouble() * 1000; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public IntPoint[] FloatToIntRound() | ||
{ | ||
var points = new IntPoint[_xs.Length]; | ||
for (int i = 0; i < _xs.Length; i++) | ||
{ | ||
points[i] = new IntPoint | ||
{ | ||
X = (int)MathF.Round(_xs[i]), | ||
Y = (int)MathF.Round(_ys[i]) | ||
}; | ||
} | ||
|
||
return points; | ||
} | ||
|
||
[Benchmark] | ||
public IntPoint[] FloatToIntAdd() | ||
{ | ||
var points = new IntPoint[_xs.Length]; | ||
for (int i = 0; i < _xs.Length; i++) | ||
{ | ||
points[i] = new IntPoint | ||
{ | ||
X = (int)(_xs[i] + 0.5f), | ||
Y = (int)(_ys[i] + 0.5f) | ||
}; | ||
} | ||
|
||
return points; | ||
} | ||
|
||
|
||
public struct IntPoint | ||
{ | ||
public int X; | ||
public int Y; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\GdsSharp.Lib\GdsSharp.Lib.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.14.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReverse.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReverseFactorExtract.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReversePrealloc.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderSpan.cs" /> | ||
<Compile Remove="PathBuilder\IPathBuilder.cs" /> | ||
<Compile Remove="PathBuilder\PathBuilderBenchmark.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderArray.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReverse.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReverseFactorExtract.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReversePrealloc.cs" /> | ||
<Compile Remove="PathBuilder\Implementations\PathBuilderListReverseSpan.cs" /> | ||
<Compile Remove="PathBuilder\IPathBuilder.cs" /> | ||
<Compile Remove="PathBuilder\PathBuilderBase.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[assembly: Parallelizable(ParallelScope.All)] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.