繁体   English   中英

在Silverlight 5中异步/等待性能

[英]Async/Await performance within Silverlight 5

我最近对Silverlight 5中的async / await(asyncctp)功能进行了一些测试。

以下硬件用于两个测试:

  • Intel snb 2.3g
  • 8g DDR
  • Windows 7 - 64位
  • Silverlight 5
  • SQL Server 2008 - R2

测试逻辑如下:

  1. 没有异步/等待:

     public void LoadMasterItem(string strUNIT_ID) { **DateTime dt = DateTime.Now;** ctx.OBS_UNITs.Clear(); this.IsMasterItemBusy = true; ctx.Load(ctx.GetOBS_UNITQuery().Where(p => p.UNIT_ID == strUNIT_ID)).Completed += (sender, e) => { this.MasterItem = ctx.OBS_UNITs.FirstOrDefault(); this.IsMasterItemBusy = false; LoadDataArgs args = ExceptionManager.CheckDataContextResult(sender, args); **var ts = DateTime.Now.Subtract(dt).Ticks;** **string str = ts.ToString();** }; } 
  2. 使用async / await:

     public **async** Task<LoadDataArgs> LoadMasterItem(string UNIT_ID) { **DateTime dt = DateTime.Now;** ctx.OBS_UNITs.Clear(); var oper = await ctx.Load(ctx.GetOBS_UNITQuery().Where(p => p.UNIT_ID == UNIT_ID)).AsTask(); LoadDataArgs args = ExceptionManager.CheckDataContextResult(oper); if (args.LoadState) { this.MasterItem = oper.Entities.FirstOrDefault(); } **var ts = DateTime.Now.Subtract(dt).Ticks;** **string str = ts.ToString();** return args; } 

实验1的得分:5304010
实验2:30001的蜱虫

我很好奇为什么以及如何使用async / await将我的Silverlight应用程序提升到如此显着的程度。 如果我的测试“不公平”,请同时给我一些关于如何改进它们的评论。


我已将“str”值绑定到不使用调试模式的UI。 它们托管在IIS中并在IE9中执行。

结果如下:

得1:5504010
得分为2:5680325

感谢您的回复,似乎我在实际表现上犯了一个错误。

当您检查第二个样本中的时间时,我认为加载操作实际上并未完成。 该方法返回异步执行的任务,并不一定意味着从异步方法返回时已执行加载。

await运算符只是为了帮助您的代码在处理链接调用时更具可读性和更简单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM