Skip to content

Commit

Permalink
Formatted files in project.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Sep 18, 2024
1 parent c768457 commit effb9dd
Show file tree
Hide file tree
Showing 157 changed files with 5,646 additions and 5,631 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
<ItemGroup>
<ProjectReference Include="..\Schema\Schema.csproj" />
</ItemGroup>
</Project>
</Project>
14 changes: 7 additions & 7 deletions Benchmarks/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ 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));
}
var summary = BenchmarkRunner.Run<ReadingValues>(
ManualConfig
.Create(DefaultConfig.Instance)
.AddDiagnoser(
new MemoryDiagnoser(new MemoryDiagnoserConfig(true)))
.WithOptions(ConfigOptions.DisableOptimizationsValidator));
}
}
18 changes: 9 additions & 9 deletions Benchmarks/StreamComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ public class StreamComparison {

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

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

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

for (var i = 0; i < n; i++) {
var b = reader.ReadByte();
}
for (var i = 0; i < n; i++) {
var b = reader.ReadByte();
}
}
}
42 changes: 21 additions & 21 deletions Benchmarks/StringBuilderComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ public class StringBuilderComparison {

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

for (var i = 0; i < n; i++) {
sb.Append('0');
}

var str = sb.ToString();
for (var i = 0; i < n; i++) {
sb.Append('0');
}

var str = sb.ToString();
}
}

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

for (var i = 0; i < n; i++) {
sb.Append('0');
}
for (var iteration = 0; iteration < w; ++iteration) {
var sb = ZString.CreateStringBuilder();

var str = sb.ToString();
for (var i = 0; i < n; i++) {
sb.Append('0');
}

var str = sb.ToString();
}
}

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

for (var i = 0; i < n; i++) {
sb.Append('0');
}
for (var iteration = 0; iteration < w; ++iteration) {
var sb = ZString.CreateUtf8StringBuilder();

var str = sb.ToString();
for (var i = 0; i < n; i++) {
sb.Append('0');
}

var str = sb.ToString();
}
}
}
32 changes: 16 additions & 16 deletions Benchmarks/StringComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ public class StringComparison {

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

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

Span<char> c = stackalloc char[n];
for (var i = 0; i < n; i++) {
c[i] = (char) this.stream_.ReadByte();
}
Span<char> c = stackalloc char[n];
for (var i = 0; i < n; i++) {
c[i] = (char) this.stream_.ReadByte();
}
}
}

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

Span<byte> buffer = stackalloc byte[n];
this.stream_.Read(buffer);
Span<byte> buffer = stackalloc byte[n];
this.stream_.Read(buffer);

Span<char> c = stackalloc char[n];
for (var i = 0; i < n; i++) {
c[i] = (char) buffer[i];
}
Span<char> c = stackalloc char[n];
for (var i = 0; i < n; i++) {
c[i] = (char) buffer[i];
}
}
}
}
14 changes: 7 additions & 7 deletions Schema Build Tests/attributes/sequence/ClassSequenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public override bool Equals(object other) {
public void TestWriteAndReadArrayObject() {
var expectedSw = new ClassArraySequenceWrapper {
Values = new[] {
new SchemaClass {Value = 1},
new SchemaClass {Value = 2},
new SchemaClass {Value = 3}
new SchemaClass { Value = 1 },
new SchemaClass { Value = 2 },
new SchemaClass { Value = 3 }
}
};

Expand All @@ -67,9 +67,9 @@ public void TestWriteAndReadArrayObject() {
public void TestWriteAndReadArrayValues() {
var expectedSw = new ClassArraySequenceWrapper {
Values = new[] {
new SchemaClass {Value = 1},
new SchemaClass {Value = 2},
new SchemaClass {Value = 3}
new SchemaClass { Value = 1 },
new SchemaClass { Value = 2 },
new SchemaClass { Value = 3 }
}
};

Expand Down Expand Up @@ -106,7 +106,7 @@ public override bool Equals(object other) {
public void TestWriteAndReadListObject() {
var expectedSw = new ClassListSequenceWrapper {
Values = new List<SchemaClass> {
new() {Value = 1}, new() {Value = 2}, new() {Value = 3}
new() { Value = 1 }, new() { Value = 2 }, new() { Value = 3 }
}
};

Expand Down
112 changes: 56 additions & 56 deletions Schema Build Tests/attributes/sequence/ISequenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ public partial class MutableSequenceWrapper1 : IBinaryConvertible {
public MutableSequenceImpl<IntWrapper> Sequence { get; } = new();

public override bool Equals(object? otherObj) {
if (otherObj is MutableSequenceWrapper1 other) {
return this.Sequence.Equals(other.Sequence);
}

return false;
if (otherObj is MutableSequenceWrapper1 other) {
return this.Sequence.Equals(other.Sequence);
}

return false;
}
}

[Test]
public void TestWriteAndRead1() {
var expectedSw = new MutableSequenceWrapper1();
expectedSw.Sequence.AddRange(
new[] {1, 2, 3, 4, 5, 9, 8, 7, 6}
.Select(value => new IntWrapper {Value = value}));
var expectedSw = new MutableSequenceWrapper1();
expectedSw.Sequence.AddRange(
new[] { 1, 2, 3, 4, 5, 9, 8, 7, 6 }
.Select(value => new IntWrapper { Value = value }));

var ms = new MemoryStream();
var ms = new MemoryStream();

var endianness = Endianness.BigEndian;
var ew = new SchemaBinaryWriter(endianness);
var endianness = Endianness.BigEndian;
var ew = new SchemaBinaryWriter(endianness);

expectedSw.Write(ew);
ew.CompleteAndCopyTo(ms);
Assert.AreEqual(4 + 9 * 4, ms.Position);
expectedSw.Write(ew);
ew.CompleteAndCopyTo(ms);
Assert.AreEqual(4 + 9 * 4, ms.Position);

ms.Position = 0;
var er = new SchemaBinaryReader(ms, endianness);
var actualSw = er.ReadNew<MutableSequenceWrapper1>();
ms.Position = 0;
var er = new SchemaBinaryReader(ms, endianness);
var actualSw = er.ReadNew<MutableSequenceWrapper1>();

Assert.AreEqual(expectedSw, actualSw);
}
Assert.AreEqual(expectedSw, actualSw);
}


[BinarySchema]
Expand All @@ -63,36 +63,36 @@ public int Count {
public MutableSequenceImpl<IntWrapper> Sequence { get; } = new();

public override bool Equals(object? otherObj) {
if (otherObj is MutableSequenceWrapper2 other) {
return this.Sequence.Equals(other.Sequence);
}

return false;
if (otherObj is MutableSequenceWrapper2 other) {
return this.Sequence.Equals(other.Sequence);
}

return false;
}
}

[Test]
public void TestWriteAndRead2() {
var expectedSw = new MutableSequenceWrapper2();
expectedSw.Sequence.AddRange(
new[] {1, 2, 3, 4, 5, 9, 8, 7, 6}
.Select(value => new IntWrapper {Value = value}));
var expectedSw = new MutableSequenceWrapper2();
expectedSw.Sequence.AddRange(
new[] { 1, 2, 3, 4, 5, 9, 8, 7, 6 }
.Select(value => new IntWrapper { Value = value }));

var ms = new MemoryStream();
var ms = new MemoryStream();

var endianness = Endianness.BigEndian;
var ew = new SchemaBinaryWriter(endianness);
var endianness = Endianness.BigEndian;
var ew = new SchemaBinaryWriter(endianness);

expectedSw.Write(ew);
ew.CompleteAndCopyTo(ms);
Assert.AreEqual(4 + 9 * 4, ms.Position);
expectedSw.Write(ew);
ew.CompleteAndCopyTo(ms);
Assert.AreEqual(4 + 9 * 4, ms.Position);

ms.Position = 0;
var er = new SchemaBinaryReader(ms, endianness);
var actualSw = er.ReadNew<MutableSequenceWrapper2>();
ms.Position = 0;
var er = new SchemaBinaryReader(ms, endianness);
var actualSw = er.ReadNew<MutableSequenceWrapper2>();

Assert.AreEqual(expectedSw, actualSw);
}
Assert.AreEqual(expectedSw, actualSw);
}


[BinarySchema]
Expand Down Expand Up @@ -122,40 +122,40 @@ public T this[int index] {
public void Clear() => this.impl_.Clear();

public void ResizeInPlace(int newLength) {
SequencesUtil.ResizeSequenceInPlace(this.impl_, newLength);
}
SequencesUtil.ResizeSequenceInPlace(this.impl_, newLength);
}

public void AddRange(IEnumerable<T> values)
=> this.impl_.AddRange(values);

public MutableSequenceImpl<T> CloneWithNewLength(int newLength) {
var sequence = new MutableSequenceImpl<T>();
sequence.AddRange(this.impl_.Resized(newLength));
return sequence;
}
var sequence = new MutableSequenceImpl<T>();
sequence.AddRange(this.impl_.Resized(newLength));
return sequence;
}

IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public IEnumerator<T> GetEnumerator() => this.impl_.GetEnumerator();

public override bool Equals(object? otherObj) {
if (otherObj is MutableSequenceImpl<T> other) {
return this.Values.SequenceEqual(other.Values);
}

return false;
if (otherObj is MutableSequenceImpl<T> other) {
return this.Values.SequenceEqual(other.Values);
}

return false;
}
}

[BinarySchema]
public partial class IntWrapper : IBinaryConvertible {
public int Value { get; set; }

public override bool Equals(object? otherObj) {
if (otherObj is IntWrapper other) {
return this.Value == other.Value;
}

return false;
if (otherObj is IntWrapper other) {
return this.Value == other.Value;
}

return false;
}
}
}
Loading

0 comments on commit effb9dd

Please sign in to comment.