C#中怎么测试从数据库读取两万条数据所用的时间?

C#中怎么测试从数据库读取两万条数据所用的时间?

倚天杖
浏览 681回答 2
2回答

缥缈止盈

C#里面的  引用using System.Diagnostics; Stopwatch st = new Stopwatch();            st.Start();            //....            st.Stop();            string time = st.ElapsedMilliseconds.ToString();

浮云间

在Sql阶段就可以做到: declare @d datetime  set @d=getdate()  Select top 20000 * from Prodtct where 1=1 order by productId desc select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate()) 在代码中也可以类似方法:在前后各取一次时间,比较即可。不过这个偶然性很大,不够准确,应该用性能测试工具,像VS2008自带的测试就很不错,第三方的压力测试也可以,像winbench,webload等,
打开App,查看更多内容
随时随地看视频慕课网APP