转自:http://bbs.csdn.net/topics/360111289, 有改动。

#include <windows.h>
#include <stdio.h>
#include <process.h>
#include<memory>
#pragma comment(lib,"ws2_32.lib")

ULONGLONG g_nReadCounts=0,g_nWriteCounts=0,g_nOtherCounts=0,g_nReadsBytes=0,g_nWriteBytes=0,g_nOtherBytes=0;
void PrintIODetails() 
{
	static DWORD lastTickCount;
	static IO_COUNTERS lastIoCounters;
	DWORD tickCount;
	IO_COUNTERS ioCounters;
	static int firstTime = 1;

	tickCount = GetTickCount();
	if (!GetProcessIoCounters(GetCurrentProcess(), &ioCounters)) {
		return;
	}

	if (firstTime) 
	{
		firstTime = 0;
		printf("    Time    Reads   Writes   Others     Read(Bytes)    Write(Bytes)    Other(Bytes)\n");
		printf("--------------------------------------------------------------------------------\n");
	}
	else 
	{
		printf("%8lu%8llu%8llu%8llu%16llu%16llu%16llu\n",
			tickCount - lastTickCount,
			ioCounters.ReadOperationCount - lastIoCounters.ReadOperationCount,
			ioCounters.WriteOperationCount - lastIoCounters.WriteOperationCount,
			ioCounters.OtherOperationCount - lastIoCounters.OtherOperationCount,
			ioCounters.ReadTransferCount - lastIoCounters.ReadTransferCount,
			ioCounters.WriteTransferCount - lastIoCounters.WriteTransferCount,
			ioCounters.OtherTransferCount - lastIoCounters.OtherTransferCount
			);

		g_nReadCounts += (ioCounters.ReadOperationCount - lastIoCounters.ReadOperationCount);
		g_nWriteCounts += (ioCounters.WriteOperationCount - lastIoCounters.WriteOperationCount);
		g_nOtherCounts += (ioCounters.OtherOperationCount - lastIoCounters.OtherOperationCount);
		g_nReadsBytes += (ioCounters.ReadTransferCount - lastIoCounters.ReadTransferCount);
		g_nWriteBytes += (ioCounters.WriteTransferCount - lastIoCounters.WriteTransferCount);
		g_nOtherBytes += (ioCounters.OtherTransferCount - lastIoCounters.OtherTransferCount);
	}

	lastTickCount = tickCount;
	memcpy(&lastIoCounters, &ioCounters, sizeof(IO_COUNTERS));
}
#define PACKCOUNT 10
#define BUFFSIEZ 50000
volatile bool bWorkThreadFinish = false;
void workerThread(void * dummy) 
{
	int i;
	FILE * fp;
	char buff[BUFFSIEZ];
	WSADATA wsaData;
	SOCKET s;
	struct sockaddr_in localAddr;
	struct sockaddr_in peerAddr;

	memset(buff, 'X', sizeof(buff));

	Sleep(2000);

	// 写文件
	fp = fopen("io.txt", "w");
	if (fp) {
		printf("fwrite = %d\n", fwrite(buff, 1, sizeof(buff), fp));
		Sleep(10000);
		// 关闭文件,测试Flush
		printf("fclose\n");
		fclose(fp);
		Sleep(2000);
	}

	// 读文件
	fp = fopen("io.txt", "r");
	if (fp) {
		printf("fread = %d\n", fread(buff, 1, sizeof(buff), fp));
		fclose(fp);
		Sleep(2000);
	}

	// 网络发

	memset((void *)&localAddr, 0, sizeof(localAddr));
	localAddr.sin_family = AF_INET;
	localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	localAddr.sin_port = htons(0);
	memset((void *)&peerAddr, 0, sizeof(peerAddr));
	peerAddr.sin_family = AF_INET;
	peerAddr.sin_addr.s_addr = inet_addr("10.19.85.1");
	peerAddr.sin_port = htons(3389);

	printf("WSAStartup\n");
	WSAStartup(MAKEWORD(2, 2), &wsaData);
	Sleep(2000);

	// UDP
	printf("UDP Test:\n");
	printf("socket\n");
	s = socket(AF_INET, SOCK_DGRAM, 0);
	Sleep(2000);

	printf("bind\n");
	bind(s, (struct sockaddr *)&localAddr, sizeof(localAddr));
	Sleep(2000);
	for (i = 0; i < PACKCOUNT; i++) {
		printf("sendto = %d\n", sendto(s, buff, i * 100, 0, (SOCKADDR *) &peerAddr, sizeof(peerAddr)));
		Sleep(2000);
	}
	printf("closesocket\n");
	closesocket(s);
	Sleep(2000);

	// TCP
	printf("TCP Test:\n");
	printf("socket\n");
	s = socket(AF_INET, SOCK_STREAM, 0);
	Sleep(2000);

	printf("bind\n");
	bind(s, (struct sockaddr *)&localAddr, sizeof(localAddr));
	Sleep(2000);

	printf("connect\n");
	connect(s, (SOCKADDR *) &peerAddr, sizeof(peerAddr));
	Sleep(2000);

	printf("send = %d\n", send(s, buff, sizeof(buff), 0));
	Sleep(2000);

	printf("closesocket\n");
	closesocket(s);
	Sleep(2000);

	printf("WSACleanup\n");
	WSACleanup();

	bWorkThreadFinish = true;
}

UINT _stdcall ThreadProc(PVOID pv)
{
	workerThread(pv);
	return 1;
}
//HANDLE g_hEvt = NULL;
int main(int argc, char ** argv) 
{
	// 启动工作线程
	::_beginthreadex(NULL,0,ThreadProc,NULL,0,0);

	//g_hEvt = ::CreateEventW(NULL,FALSE,FALSE,NULL);
	

	printf("Ctrl-C to exit\n\n");
	for (;;) 
	{
		PrintIODetails();
		Sleep(1000);
		if (bWorkThreadFinish)
		{
			break;
		}	
	}
	printf("*********************************Total*************************************\n");
	printf("    Reads   Writes   Others     Read(Bytes)    Write(Bytes)    Other(Bytes)\n");
	printf("%8llu%8llu%8llu%16llu%16llu%16llu\n",
		g_nReadCounts,
		g_nWriteCounts,
		g_nOtherCounts,
		g_nReadsBytes,
		g_nWriteBytes,
		g_nOtherBytes
		);
	return 0;
}

Windows IO 性能简单测试的更多相关文章

  1. 记一次虚拟化环境下Windows IO性能的解析

    前言随着云计算技术与服务的发展和进步,越来越多的客户选择将业务部署到云端.但由于引入了虚拟化层,在业务部署过程中经常会遇到IO问题,通常也不易调试.本文主要介绍利用perf.systemtap等工具, ...

  2. MySQL中MyISAM引擎与InnoDB引擎性能简单测试

    [硬件配置]CPU : AMD2500+ (1.8G)内存: 1G/现代硬盘: 80G/IDE[软件配置]OS : Windows XP SP2SE : PHP5.2.1DB : MySQL5.0.3 ...

  3. windows上测试磁盘io性能

    一.问题由来 前两天搭建一套演示环境,同样的java war包,放在我们这边服务器好好的,放在那边就运行缓慢. 后来把日志改成异步之后就好了. 后边找了个程序测了下io性能,竟然差了7,8倍. 二.软 ...

  4. 磁盘IO性能监控(Linux 和 Windows)

    磁盘IO性能监控(Linux 和 Windows) 作者:终南   <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...

  5. Linux如何查看与测试磁盘IO性能

    1. 查看磁盘 IO 性能 1.1 top 命令 top 命令通过查看 CPU 的 wa% 值来判断当前磁盘 IO 性能,如果这个数值过大,很可能是磁盘 IO 太高了,当然也可能是其他原因,例如网络 ...

  6. Linux 如何测试 IO 性能(磁盘读写速度)

    这几天做MySQL性能测试,偌大一个公司,找几台性能测试机器都很纠结,终于协调到两台,IO的性能如何还不知道.数据库属于IO密集型的应用,所以还是先评估下Server的IO性能,看看是否能和线上的机器 ...

  7. 在Windows中监视IO性能

    附:在Windows中监视IO性能 本来准备写一篇windows中监视IO性能的,后来发现好像可写的内容不多,windows在细节这方面做的不是那么的好,不过那些基本信息还是有的. 在Windows中 ...

  8. windows集群简单介绍

    windows集群简单介绍仔细看过以前网友发表的一些文章,总觉得对windows集群没有详细介绍,我也是借花献佛,引用了一些技术性文档.目前应用最为广泛的集群计算技术可以分为三大类:高可用性集群技术. ...

  9. 在Linux中监视IO性能

    dd命令 iostat命令 理解iostat的各项输出 iostat的应用实例 附:在Windows中监视IO性能 延伸阅读 dd命令 dd其实是工作于比较低层的一个数据拷贝和转换的*nix平台的工具 ...

随机推荐

  1. 利用 Nginx 做反向代理解决微信小程序业务域名限制问题

    参考网站:(下述两个参考网站可以完美解决问题) https://www.jianshu.com/p/47eff6eeec25 https://www.cnblogs.com/kenwar/p/8288 ...

  2. ASP.NET Core中Middleware的使用

    https://www.cnblogs.com/shenba/p/6361311.html   ASP.NET 5中Middleware的基本用法 在ASP.NET 5里面引入了OWIN的概念,大致意 ...

  3. Python 实现flatten功能

    from collections import Iterable def flatten(items): for x in items: if isinstance(x, Iterable) and ...

  4. 10个重要的算法C语言实现源代码

    包括拉格朗日,牛顿插值,高斯,龙贝格,牛顿迭代,牛顿-科特斯,雅克比,秦九昭,幂法,高斯塞德尔 .都是经典的数学算法,希望能开托您的思路.转自kunli.info 1.拉格朗日插值多项式 ,用于离散数 ...

  5. Mybatis 关联查询(二

    一对多的管理查询结果映射   1.进行一对多的查询时候,要在主查询表对应的Po中加入关联查询表对应PO的类的list集合作为属性. public class Orders { private Inte ...

  6. win10中VirtualBox联网设置

    <分享>关于win10操作系统中VirtualBox无法桥接的解决方法 版权声明:本文为博主原创文章,未经博主允许不得转载. 升级win10,本来是一件很好的事,想好好体验一下新版本的感觉 ...

  7. Backup Log

    使用Backup Log 命令可进行数据库的事务日志备份.其语法格式如下: Backup 数据库名 To 备份设备 和备份数据库操作一样

  8. JMS - ActiveMQ的简单使用

    首先需要下载ActiveMQ,下面的链接给我们列出了所有版本:http://activemq.apache.org/download-archives.html每个版本为不同的OS提供了链接: 公司电 ...

  9. 【Hadoop系列】linux下 root用户免密码登录远程主机 ssh

    SSH原理:[Hadoop系列]linux SSH原理解析 操作环境: CentOS 6.5 操作对象: 用户A主机和远程主机B 正文部分:斜体加粗代表linux指令. linux下 非root用户免 ...

  10. 关于async和await的一些误区

    微软的MSDN说async和await是“异步”,但是不少人(包括笔者自己)有一些误区需要澄清:为什么await语句之后没有执行?不是异步吗? [示例代码] public partial class ...