Skip to content

Commit

Permalink
Switched all files to file-scoped namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Aug 13, 2024
1 parent e7e51d9 commit 355b20f
Show file tree
Hide file tree
Showing 278 changed files with 13,065 additions and 13,023 deletions.
8 changes: 4 additions & 4 deletions Benchmarks/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
using BenchmarkDotNet.Running;


namespace benchmarks {
public class Program {
public static void Main(string[] args) {
namespace benchmarks;

public class Program {
public static void Main(string[] args) {
var summary = BenchmarkRunner.Run<ReadingValues>(
ManualConfig
.Create(DefaultConfig.Instance)
.AddDiagnoser(
new MemoryDiagnoser(new MemoryDiagnoserConfig(true)))
.WithOptions(ConfigOptions.DisableOptimizationsValidator));
}
}
}
86 changes: 43 additions & 43 deletions Benchmarks/ReadingValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,63 @@
using schema.binary;


namespace benchmarks {
[MemoryDiagnoser]
public class ReadingValues {
public const int w = 1000;
public const int m = 4;
public const int n = 10000;
namespace benchmarks;

[Params(Endianness.BigEndian, Endianness.LittleEndian)]
public Endianness Endianness { get; set; }
[MemoryDiagnoser]
public class ReadingValues {
public const int w = 1000;
public const int m = 4;
public const int n = 10000;

[Params(Endianness.BigEndian, Endianness.LittleEndian)]
public Endianness Endianness { get; set; }

private readonly Stream stream_ = new MemoryStream(m * n);

private SchemaBinaryReader BinaryReader { get; set; }
private readonly Stream stream_ = new MemoryStream(m * n);

[IterationSetup]
public void BeforeEach() {
this.BinaryReader
= new SchemaBinaryReader(this.stream_, this.Endianness);
}
private SchemaBinaryReader BinaryReader { get; set; }

[IterationSetup]
public void BeforeEach() {
this.BinaryReader
= new SchemaBinaryReader(this.stream_, this.Endianness);
}

[Benchmark]
public void ReadBytesSeparately() {
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
for (var i = 0; i < n; ++i) {
this.BinaryReader.ReadByte();
}
[Benchmark]
public void ReadBytesSeparately() {
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
for (var i = 0; i < n; ++i) {
this.BinaryReader.ReadByte();
}
}
}

[Benchmark]
public void ReadBytesTogether() {
Span<byte> bytes = stackalloc byte[n];
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
this.BinaryReader.ReadBytes(bytes);
}
[Benchmark]
public void ReadBytesTogether() {
Span<byte> bytes = stackalloc byte[n];
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
this.BinaryReader.ReadBytes(bytes);
}
}

[Benchmark]
public void ReadFloatsSeparately() {
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
for (var i = 0; i < n; ++i) {
this.BinaryReader.ReadSingle();
}
[Benchmark]
public void ReadFloatsSeparately() {
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
for (var i = 0; i < n; ++i) {
this.BinaryReader.ReadSingle();
}
}
}

[Benchmark]
public void ReadFloatsTogether() {
Span<float> floats = stackalloc float[n];
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
this.BinaryReader.ReadSingles(floats);
}
[Benchmark]
public void ReadFloatsTogether() {
Span<float> floats = stackalloc float[n];
for (var iteration = 0; iteration < w; iteration++) {
this.stream_.Position = 0;
this.BinaryReader.ReadSingles(floats);
}
}
}
22 changes: 11 additions & 11 deletions Benchmarks/StreamComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
using schema.util.streams;


namespace benchmarks {
public class StreamComparison {
public const int n = 10000;
private readonly Stream stream_ = new MemoryStream(n);
namespace benchmarks;

[IterationSetup]
public void BeforeEach() {
public class StreamComparison {
public const int n = 10000;
private readonly Stream stream_ = new MemoryStream(n);

[IterationSetup]
public void BeforeEach() {
this.stream_.Position = 0;
}

[Benchmark]
public void ReadByteThroughStream() {
[Benchmark]
public void ReadByteThroughStream() {
for (var i = 0; i < n; i++) {
var b = this.stream_.ReadByte();
}
}

[Benchmark]
public void ReadByteThroughWrapper() {
[Benchmark]
public void ReadByteThroughWrapper() {
var reader = new ReadableStream(this.stream_);

for (var i = 0; i < n; i++) {
var b = reader.ReadByte();
}
}
}
}
22 changes: 11 additions & 11 deletions Benchmarks/StringBuilderComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using Cysharp.Text;


namespace benchmarks {
public class StringBuilderComparison {
public const int w = 100;
public const int n = 100;
namespace benchmarks;

[Benchmark]
public void Stack() {
public class StringBuilderComparison {
public const int w = 100;
public const int n = 100;

[Benchmark]
public void Stack() {
for (var iteration = 0; iteration < w; ++iteration) {
var sb = new StringBuilder();

Expand All @@ -23,8 +24,8 @@ public void Stack() {
}
}

[Benchmark]
public void Heap16() {
[Benchmark]
public void Heap16() {
for (var iteration = 0; iteration < w; ++iteration) {
var sb = ZString.CreateStringBuilder();

Expand All @@ -36,8 +37,8 @@ public void Heap16() {
}
}

[Benchmark]
public void Heap8() {
[Benchmark]
public void Heap8() {
for (var iteration = 0; iteration < w; ++iteration) {
var sb = ZString.CreateUtf8StringBuilder();

Expand All @@ -48,5 +49,4 @@ public void Heap8() {
var str = sb.ToString();
}
}
}
}
26 changes: 13 additions & 13 deletions Benchmarks/StringComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
using BenchmarkDotNet.Attributes;


namespace benchmarks {
public class StringComparison {
public const int w = 100;
public const int n = 100;
private readonly Stream stream_ = new MemoryStream(n);

[IterationSetup]
public void BeforeEach() {
namespace benchmarks;

public class StringComparison {
public const int w = 100;
public const int n = 100;
private readonly Stream stream_ = new MemoryStream(n);

[IterationSetup]
public void BeforeEach() {
this.stream_.Position = 0;
}

[Benchmark]
public void ReadCharsSeparately() {
[Benchmark]
public void ReadCharsSeparately() {
for (var iteration = 0; iteration < w; ++iteration) {
this.stream_.Position = 0;

Expand All @@ -27,8 +28,8 @@ public void ReadCharsSeparately() {
}
}

[Benchmark]
public void ReadCharsViaByteBuffer() {
[Benchmark]
public void ReadCharsViaByteBuffer() {
for (var iteration = 0; iteration < w; ++iteration) {
this.stream_.Position = 0;

Expand All @@ -41,5 +42,4 @@ public void ReadCharsViaByteBuffer() {
}
}
}
}
}
52 changes: 26 additions & 26 deletions Schema Build Tests/attributes/sequence/ClassSequenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,39 @@
using schema.binary.attributes;


namespace build {
public partial class ClassSequenceTests {
[BinarySchema]
public partial class SchemaClass : IBinaryConvertible {
public int Value { get; set; }
namespace build;

public override bool Equals(object other) {
public partial class ClassSequenceTests {
[BinarySchema]
public partial class SchemaClass : IBinaryConvertible {
public int Value { get; set; }

public override bool Equals(object other) {
if (other is SchemaClass otherStruct) {
return this.Value.Equals(otherStruct.Value);
}

return false;
}
}
}


[BinarySchema]
public partial class ClassArraySequenceWrapper : IBinaryConvertible {
[SequenceLengthSource(SchemaIntegerType.BYTE)]
public SchemaClass[] Values { get; set; }
[BinarySchema]
public partial class ClassArraySequenceWrapper : IBinaryConvertible {
[SequenceLengthSource(SchemaIntegerType.BYTE)]
public SchemaClass[] Values { get; set; }

public override bool Equals(object other) {
public override bool Equals(object other) {
if (other is ClassArraySequenceWrapper otherSequenceWrapper) {
return this.Values.SequenceEqual(otherSequenceWrapper.Values);
}

return false;
}
}
}

[Test]
public void TestWriteAndReadArrayObject() {
[Test]
public void TestWriteAndReadArrayObject() {
var expectedSw = new ClassArraySequenceWrapper {
Values = new[] {
new SchemaClass {Value = 1},
Expand All @@ -62,8 +63,8 @@ public void TestWriteAndReadArrayObject() {
Assert.AreEqual(expectedSw, actualSws);
}

[Test]
public void TestWriteAndReadArrayValues() {
[Test]
public void TestWriteAndReadArrayValues() {
var expectedSw = new ClassArraySequenceWrapper {
Values = new[] {
new SchemaClass {Value = 1},
Expand All @@ -87,22 +88,22 @@ public void TestWriteAndReadArrayValues() {
}


[BinarySchema]
public partial class ClassListSequenceWrapper : IBinaryConvertible {
[SequenceLengthSource(SchemaIntegerType.BYTE)]
public List<SchemaClass> Values { get; set; } = new();
[BinarySchema]
public partial class ClassListSequenceWrapper : IBinaryConvertible {
[SequenceLengthSource(SchemaIntegerType.BYTE)]
public List<SchemaClass> Values { get; set; } = new();

public override bool Equals(object other) {
public override bool Equals(object other) {
if (other is ClassListSequenceWrapper otherSequenceWrapper) {
return this.Values.SequenceEqual(otherSequenceWrapper.Values);
}

return false;
}
}
}

[Test]
public void TestWriteAndReadListObject() {
[Test]
public void TestWriteAndReadListObject() {
var expectedSw = new ClassListSequenceWrapper {
Values = new List<SchemaClass> {
new() {Value = 1}, new() {Value = 2}, new() {Value = 3}
Expand All @@ -122,5 +123,4 @@ public void TestWriteAndReadListObject() {
var actualSw = er.ReadNew<ClassListSequenceWrapper>();
Assert.AreEqual(expectedSw, actualSw);
}
}
}
Loading

0 comments on commit 355b20f

Please sign in to comment.