Skip to content

Instantly share code, notes, and snippets.

@stephentoub
Last active June 6, 2017 23:06
Timing Encoding.UTF8.GetBytes
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
public class Test
{
public static void Main()
{
string s = new string(Enumerable.Range(0, 1024).Select(i => (char)('a' + i)).ToArray());
while (true)
{
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1_000_000; i++)
{
byte[] data = Encoding.UTF8.GetBytes(s);
}
Console.WriteLine(sw.Elapsed);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment