-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve MemoryPackSerializer.Deserialize(Stream) performance
- Loading branch information
Showing
6 changed files
with
122 additions
and
10 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
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
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
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,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MemoryPack.Tests; | ||
|
||
public class StreamOptimizeTest | ||
{ | ||
[Fact] | ||
public async Task MemoryStream() | ||
{ | ||
var ms = new MemoryStream(); | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 1, 2, 3 }); | ||
var offset = ms.Position; | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 10, 20, 30 }); | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 40, 50, 60 }); | ||
|
||
ms.Position = offset; | ||
|
||
var data1 = await MemoryPackSerializer.DeserializeAsync<int[]>(ms); | ||
var data2 = await MemoryPackSerializer.DeserializeAsync<int[]>(ms); | ||
|
||
data1.Should().Equal(10, 20, 30); | ||
data2.Should().Equal(40, 50, 60); | ||
} | ||
|
||
[Fact] | ||
public async Task MemoryStreamNoGenerics() | ||
{ | ||
var ms = new MemoryStream(); | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 1, 2, 3 }); | ||
var offset = ms.Position; | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 10, 20, 30 }); | ||
await MemoryPackSerializer.SerializeAsync(ms, new[] { 40, 50, 60 }); | ||
|
||
ms.Position = offset; | ||
|
||
var data1 = (int[]?)await MemoryPackSerializer.DeserializeAsync(typeof(int[]), ms); | ||
var data2 = (int[]?)await MemoryPackSerializer.DeserializeAsync(typeof(int[]), ms); | ||
|
||
data1.Should().Equal(10, 20, 30); | ||
data2.Should().Equal(40, 50, 60); | ||
} | ||
} |