Windows IO 性能简单测试

转自: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 性能简单测试,布布扣,bubuko.com

时间: 2024-10-06 03:09:53

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

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

前言随着云计算技术与服务的发展和进步,越来越多的客户选择将业务部署到云端.但由于引入了虚拟化层,在业务部署过程中经常会遇到IO问题,通常也不易调试.本文主要介绍利用perf.systemtap等工具,帮助一位托管云客户调试IO性能问题,来分析虚拟环境下Windows IO的性能. 问题出现有一次,托管云客户自己搭建了虚拟化环境,在同一台宿主机上创建windows 2008 R2 和 Centos6.5虚拟机,用fio分别测试其随机读性能,windows 2008 R2的IOPS大约在18K,而L

EntityFramework 性能简单测试

EntityFramework 的便捷不多阐述, 就他的性能来测试了下  不做评论,   缓存机制确实还不错  .... 简单的查询一条数据 1 public static IM_CallRecord GetEFData() 2 { 3 using (ModelContainer mv = new ModelContainer()) 4 { 5 return (from c in mv.IM_CallRecord where c.id == 12356 select c).SingleOrDef

sqlite性能简单测试

主要测试sqlite在大数据量下的插入及查询性能: 测试环境:Centos6.4  1G内存  单核 数据量 大小 索引字段检索(耗时) 非索引字段检索(耗时) 总插入时间 10W 19M 0.001s 0.036s 5.1s 50W 100M 0.0014s 0.147s 32.21s 100W 200M 0.0009s 5.277s 63.29s 200W 400M 0.0008s 12.51s 130.2s 500W 1002M 0.0016s 17.3s 513.1s 1000W 2G

Java学习-排序二叉树性能简单测试

1.创建4万个随机数,然后用分别用冒泡法,选择法,二叉树法3种排序算法进行排序,比较哪种更快 1 package Collection; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 public class sortSpeedTest { 7 8 public static void main(String[] args) { 9 int num = 40000; // 元素个数 10 int rnd1[] = new

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

这几天做MySQL性能测试,偌大一个公司,找几台性能测试机器都很纠结,终于协调到两台,IO的性能如何还不知道.数据库属于IO密集型的应用,所以还是先评估下Server的IO性能,看看是否能和线上的机器匹配上. 之前一直知道用dd(device to device)命令可以简单测试磁盘的IO读写速度,但没有深究.但这次做性能测试的关系,需要得到一个相对精确的值(之前的测试吃过这方面的亏,插个题外话,性能测试一定要首先确认好测试环境.). 网上常见的方法是使用hdparm和dd命令来测试,但实际的使

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

作者:终南   <[email protected]> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了iostat命令来获却磁盘输入/输出(即IO)统计信息,Windows则提供了WMI接口,可以通过编写一个简单的脚本来获取与iostat相当的功能. 1.Linux下的iostat命令 iostat -d -k -t 2 每隔2秒统计一次磁盘IO信息,直到按Ctrl+C终止程序,-d 选项表示统计磁盘信息, -k 表示以每秒KB的形式显示,-t 要求打印出时间信息,2 表示

SQLIOSim 模拟SQLServer的行为来测试IO性能

SQLIOSim 功能: 模拟SQLServer的行为来测试IO性能. SQLIOSim的版本: (1) SQL Server 2005的SQLIOSim是需要上网下载的套件. (2) 从SQL Server 2008开始,SQLIOSim会包含在SQL Sever安装内.对于SQL Server 2008 R2,该应用程序所在目录为C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn. (3) SQLIO

ab工具使用(测试平台的并发性能)简单介绍一下

Apache -- ab工具主要测试网站的(并发性能) 这个工具非常的强大. 基本语法 :   cmd>ab.exe –n 请求总次数  -c 并发数 请求页面的url    进入到ab.exe目录 举例:  cmd>ab.exe –n 10000 –c 100 http://localhost/test.php 简单test结果简单介绍一下: ab工具使用(测试平台的并发性能)简单介绍一下

memcached window版 下载安装,简单测试

官网: http://www.memcached.org/ 只有tag格式的,搞了好久都没找到windows版的,还有很多uri找不开,google的都打不开,中国政府就是威武. 下载地址: http://jehiah.cz/projects/memcached-win32/files/memcached-1.2.1-win32.zip 这个用讯雷可以下载下来! 错误: 通过cmd命令行进入到D:\webEve\memcached(下载后的解压目录) 运行 memcached.exe -d in