Created
April 6, 2016 15:59
-
-
Save rionmonster/4155849379f36855ca1a36c208846a42 to your computer and use it in GitHub Desktop.
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
static void Main(string[] args) | |
{ | |
// Create a stopwatch for performance testing | |
var stopwatch = new Stopwatch(); | |
// Test content | |
var data = GetTestingBytes(); | |
// Looping Test | |
using (var s1 = new MemoryStream()) | |
{ | |
stopwatch.Start(); | |
foreach (var item in data) | |
{ | |
s1.WriteByte(item); | |
} | |
stopwatch.Stop(); | |
Console.WriteLine($"Loop Test: {stopwatch.Elapsed}"); | |
} | |
using (var s2 = new MemoryStream()) | |
{ | |
stopwatch.Start(); | |
s2.Write(data, 0, data.Length); | |
stopwatch.Stop(); | |
Console.WriteLine($"All At Once Test: {stopwatch.Elapsed}"); | |
} | |
Console.Read(); | |
} | |
static byte[] GetTestingBytes() | |
{ | |
var str = String.Join(",", Enumerable.Range(0, 1000).Select(x => Guid.NewGuid()).ToArray()); | |
byte[] bytes = new byte[str.Length * sizeof(char)]; | |
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); | |
return bytes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment