C#Stopwatch的使用,性能测试
一,先开启开始或继续测量某个时间间隔的运行时间,然后停止,最后重置时间,输出.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class TestPerformance : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/*Var 性能测试 */
Stopwatch stw = new Stopwatch(); List<long> intlist = new List<long>();
stw.Start();
for (long i = ; i < ; i++)
{
var index = i;//使用var转入和转出
intlist.Add(index);
}
stw.Stop();
Label1.Text= stw.Elapsed.Ticks.ToString();
stw.Reset(); /*Int 性能测试 */ List<long> intlist2 = new List<long>();
stw.Start();//开始时间
for (long i = ; i < ; i++)
{
long index = i;//使用int转入和转出
intlist2.Add(index);
}
stw.Stop();
Label2.Text = stw.Elapsed.Ticks.ToString();
stw.Reset(); /*Object性能测试 */
stw.Start();//开始时间 List<long> intlist3 = new List<long>();
for (long i = ; i < ; i++)
{
object index = i;//使用object转入和转出
intlist3.Add((long)index);
}
stw.Stop();
Label3.Text = stw.Elapsed.Ticks.ToString();
}
}
二,前端显示
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPerformance.aspx.cs" Inherits="TestPerformance" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Var:<asp:Label ID="Label1" runat="server" Text="Var"></asp:Label><br/>
Int:<asp:Label ID="Label2" runat="server" Text="Int"></asp:Label><br/>
Object:<asp:Label ID="Label3" runat="server" Text="Object"></asp:Label>
</div>
</form>
</body>
</html>
三,显示结果
C#Stopwatch的使用,性能测试的更多相关文章
- Distributed4:SQL Server 分布式数据库性能测试
我使用三台SQL Server 2012 搭建分布式数据库,将一年的1.4亿条数据大致均匀存储在这三台Server中,每台Server 存储4个月的数据,Physical Server的配置基本相同, ...
- C#异常处理性能测试
异常处理性能测试 using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq ...
- 微型 ORM 的第二篇 DapperLambda性能测试[Dapper比较篇]
由于这周比较忙,所以本来想做的性能测试,一直没时间,想想还是今天给补上吧 由于很多人都担心性能问题,封装之后跟Dapper的性能差距是多少,今天我给出我的测试方法,仅供参考. 创建IDbConnect ...
- .net异步性能测试(包括ASP.NET MVC WebAPI异步方法)
很久没有写博客了,今年做的产品公司这两天刚刚开了发布会,稍微清闲下来,想想我们做的产品还有没有性能优化空间,于是想到了.Net的异步可以优化性能,但到底能够提升多大的比例呢?恰好有一个朋友正在做各种语 ...
- CYQ.Data 对于分布式缓存Redis、MemCache高可用的改进及性能测试
背景: 随着.NET Core 在 Linux 下的热动,相信动不动就要分布式或集群的应用的需求,会慢慢火起来. 所以这段时间一直在研究和思考分布式集群的问题,同时也在思考把几个框架的思维相对提升到这 ...
- 将不确定变为确定~老赵写的CodeTimer是代码性能测试的利器
首先,非常感谢赵老大的CodeTimer,它让我们更好的了解到代码执行的性能,从而可以让我们从性能的角度来考虑问题,有些东西可能我们认为是这样的,但经理测试并非如何,这正应了我之前的那名话:“机器最能 ...
- Distributed3:SQL Server 分布式数据库性能测试
我在三台安装SQL Server 2012的服务器上搭建分布式数据库,把产品环境中一年近1.4亿条数据大致均匀地存储在这三台服务器中,每台Server 存储4个月的数据,物理机的系统配置基本相同:内存 ...
- Entity Framework——性能测试
内容提要 一.对EF框架的性能测试 增.删.改,查测试及性能优化 二.使用sql执行 增.删.改,查测试 三.对以上两种方式对比分析 一 对EF框架的测试 1插入操作测试 测试代码(关键部分) Lis ...
- stout代码分析之六:Stopwatch
在进行性能测试时,经常需要计算某个函数执行的时长.stout中的Stopwatch类可实现纳秒精度的计时. Stopwatch内部使用timespec记录开始和技术时间. timeval和time ...
随机推荐
- 写一个MyList
首先定义接口 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- Javascript赋值语句中的“&&”操作符和"||"操作符
有这么一种常见的语句: var a = a || 4; 那赋值语句中的"&&"操作符和"||"操作符是什么意思?如何知道这两个逻辑操作符两旁的数 ...
- C#文件处理
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 用websocket实现后台推送消息
1前台实现 connect:function() { var webSocketIP = window.CRM_CONFIG.WebSocketIP; var target = 'ws://'+web ...
- mysql循环插入数据库中数据。
DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i INT DEFAULT 1; WHILE i<100 DO insert ...
- 效果网址http://sc.chinaz.com/tag_jiaoben/tupianlunbo.html
http://sc.chinaz.com/tag_jiaoben/tupianlunbo.html
- Unity3DGUI:常用控件
- XTU 1250 Super Fast Fourier Transform
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$H$题 排序,二分. 对$a$数组,$b$数组从小到大进行排序. 统计每一个$a[i]$作为较大值的时候与$b[i]$对答案的贡献.反过来再统计 ...
- asp.net 如何引用dll
这要看你引用dll文件是什么文件,是单纯的类库还是外部或自定义控件dll文件. 如果是类库dll文件,引用的步骤是这样的:在解决方案管理器中,选中要添加引用的项目或网站-右击-添加引用-选择要添加的d ...
- mybatis(1)
一.MyBatis简介 MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及结果集的检索.MyBatis ...