带有异步任务的BenchmarkDotnet



我正在尝试运行此代码:

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();
    }
}

我很确定我做错了很多事情(因为它不起作用(;我总是收到没有找到基准的消息,从我发现的样品中,我找不到如何使它起作用。

我想像1000倍的1000倍与Newtonsoft&amp;的URL相同的响应。ServiceStack并从中获得良好的基准。我该如何使此代码工作,我做错了什么?

类和方法都需要公开,不能静态。该课程也不得密封。

相关内容

  • 没有找到相关文章

最新更新