我正在尝试运行此代码:
public class Parsing
{
private const string Url ="blabla";
private static HttpClient client = new HttpClient();
private static Task<string> newton = ParseNewton();
private static Task<string> servicestack = ParseServiceStack();
[Benchmark]
private static async Task<string> ParseNewton()
{
var response = client.GetAsync(Url).Result;
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var serializer = new Newtonsoft.Json.JsonSerializer();
using (var sr = new StreamReader(stream))
using (var jsonTextReader = new JsonTextReader(sr))
{
return serializer.Deserialize<string>(jsonTextReader);
}
}
[Benchmark]
private static async Task<string> ParseServiceStack()
{
var response = client.GetAsync(Url).Result;
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<string>(stream);
}
}
电话是
internal class Program
{
public static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<Parsing>();
Console.ReadKey();
}
}
我很确定我做错了很多事情(因为它不起作用);我总是收到未找到基准的消息,并且从我发现的样本中我找不到如何使其工作。
我想反序列化来自 NewtonSoft 和 ServiceStack 给出的 url 的相同响应的 1000 倍,并从中获得良好的基准。我怎样才能使这段代码工作,我做错了什么?