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 50000volatile 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);// 关闭文件,测试Flushprintf("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);// UDPprintf("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);// TCPprintf("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 性能简单测试的更多相关文章
- 记一次虚拟化环境下Windows IO性能的解析
前言随着云计算技术与服务的发展和进步,越来越多的客户选择将业务部署到云端.但由于引入了虚拟化层,在业务部署过程中经常会遇到IO问题,通常也不易调试.本文主要介绍利用perf.systemtap等工具, ...
- MySQL中MyISAM引擎与InnoDB引擎性能简单测试
[硬件配置]CPU : AMD2500+ (1.8G)内存: 1G/现代硬盘: 80G/IDE[软件配置]OS : Windows XP SP2SE : PHP5.2.1DB : MySQL5.0.3 ...
- windows上测试磁盘io性能
一.问题由来 前两天搭建一套演示环境,同样的java war包,放在我们这边服务器好好的,放在那边就运行缓慢. 后来把日志改成异步之后就好了. 后边找了个程序测了下io性能,竟然差了7,8倍. 二.软 ...
- 磁盘IO性能监控(Linux 和 Windows)
磁盘IO性能监控(Linux 和 Windows) 作者:终南 <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...
- Linux如何查看与测试磁盘IO性能
1. 查看磁盘 IO 性能 1.1 top 命令 top 命令通过查看 CPU 的 wa% 值来判断当前磁盘 IO 性能,如果这个数值过大,很可能是磁盘 IO 太高了,当然也可能是其他原因,例如网络 ...
- Linux 如何测试 IO 性能(磁盘读写速度)
这几天做MySQL性能测试,偌大一个公司,找几台性能测试机器都很纠结,终于协调到两台,IO的性能如何还不知道.数据库属于IO密集型的应用,所以还是先评估下Server的IO性能,看看是否能和线上的机器 ...
- 在Windows中监视IO性能
附:在Windows中监视IO性能 本来准备写一篇windows中监视IO性能的,后来发现好像可写的内容不多,windows在细节这方面做的不是那么的好,不过那些基本信息还是有的. 在Windows中 ...
- windows集群简单介绍
windows集群简单介绍仔细看过以前网友发表的一些文章,总觉得对windows集群没有详细介绍,我也是借花献佛,引用了一些技术性文档.目前应用最为广泛的集群计算技术可以分为三大类:高可用性集群技术. ...
- 在Linux中监视IO性能
dd命令 iostat命令 理解iostat的各项输出 iostat的应用实例 附:在Windows中监视IO性能 延伸阅读 dd命令 dd其实是工作于比较低层的一个数据拷贝和转换的*nix平台的工具 ...
随机推荐
- Scrapy——settings配置文件
# -*- coding: utf-8 -*- # Scrapy settings for tencent project # # For simplicity, this file contains ...
- vue 路由传参 、接收参数
传参组件 一. <router-link :to='"/main/course?navName=" +item.columnName + "&id=&quo ...
- easygui.py的安装和下载地址
easygui下载地址:http://nchc.dl.sourceforge.net/project/easygui/0.97/easygui-0.97.zip 安装:解压后将easygui.py拷贝 ...
- (转)CentOS7 搭建LVS+keepalived负载均衡(一)
原文:http://blog.csdn.net/u012852986/article/details/52386306 CentOS7 搭建LVS+keepalived负载均衡(一) CentOS7 ...
- Javascript面向对象编程(转)
http://blog.csdn.net/lmj623565791/article/details/29210679 其实,从这个面向对象编程的例子来看,思路还是很清晰的. 第一步: 构造函数,用于初 ...
- Python数据类型(元组)
文章内容参考了教程:http://www.runoob.com/python/python-basic-syntax.html#commentform Python 元组 Python的元组与列表类似 ...
- 【javascript】jq之display:none与visible:hidden
今天学习到jquery的hide()部分时,突然有一个想法,jquery中的隐藏/显示部分的实现是给目标元素附加一个"display: none"属性,那么如果在类似于下面的布局中 ...
- Windows下SVN回滚到旧版本(TortoiseSVN)
当发现新提交的代码有问题,然后想将某个旧的版本作为最新的版本时,可以使用回滚, 操作步骤如下: 1. 签出(CheckOut)最新版本的代码到电脑中(不能做任何修改) 2. 执行TortoiseSVN ...
- 在web应用中使用文件
使用HTML5 DOM新增的File API,现在可以让网页要求用户选择本地文件,并且读取这些文件的信息了.选择的方式既可以是HTML<input> 元素,也可以是拖拽 . 你可以在chr ...
- jvm内置锁synchronized不能被中断
很久没看技术书籍了,今天看了一下<七周七并发模型>前面两章讲的java,写的还是有深度的.看到了一个有demo,说jvm内置锁synchronized是不能被中断的.照着书上写了个demo ...