调用 ExecuteQuerySegmented 时获取下载速度

Get download speed when ExecuteQuerySegmented is called

我知道 ExecuteQuerySegmented 针对 Azure Table 存储运行查询。我想知道调用 ExecuteQuerySegmented 时如何输出下载速度?类似于:

    var queryResult = table.ExecuteQuerySegmented(new TableQuery<TModel>(), token); 

//a decimal or double value below this line to get the download speed after the call to ExecuteQuerySegmented is executed.

如有任何建议,我们将不胜感激。

据我所知,我们无法直接获取调用ExecuteQuerySegmented的下载速度。

这里有一个解决方法,我们可以获得 ExecuteQuerySegmented 的平均下载速度。

我们可以使用 "System.Diagnostics.Stopwatch" class 来获取 table.ExecuteQuerySegmented 方法的执行时间并使用 "System.Text.Encoding.Unicode.GetByteCount(Since the response of the azure storage using json format to generate the result) to get the result's size of the "table.ExecuteQuerySegmented".

最后,我们可以使用bytes/second来计算速度。

更多详情,您可以参考以下代码:

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
             "yourstorageaccount");

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Retrieve a reference to the table.
        CloudTable table = tableClient.GetTableReference("tablename");


        string filter = TableQuery.GenerateFilterCondition(
    "PartitionKey", QueryComparisons.Equal, "Aut");

        TableContinuationToken continuationToken = null;
        TableQuery<BookTest3> query = new TableQuery<BookTest3>().Where(filter);

        var watch = System.Diagnostics.Stopwatch.StartNew();
        var queryResult = table.ExecuteQuerySegmented(query, continuationToken).Results;
        watch.Stop();
        //get the execute time
        float seconds = watch.ElapsedMilliseconds/ 1000;
       //Serialize the object
       string s = JsonConvert.SerializeObject(queryResult);
       //get bytes
        float re =   System.Text.Encoding.Unicode.GetByteCount(s)/1000;
        Console.WriteLine(re/seconds);
        Console.Read();