首页 > 作文

win 环境磁盘速度测试

更新时间:2023-04-04 02:31:21 阅读: 评论:0

#include <iostream>#include <fstream>#include <chrono>#include <vector>#include <Windows.h>VOID CALLBACK FileIOCompletionRoutine(__in  DWORD dwErrorCode,__in  DWORD dwNumberOfBytesTransfered,__in  LPOVERLAPPED lpOverlapped){}int dis困难英语kTest(){const int BLOCKS = 1024;const int BLOCK_SIZE = 1024 * 1024;auto filename = "F:/test.dat";auto start = std::chrono::high_resolution_clock::now();std::vector<char> buf(BLOCK_SIZE);auto file = std::ofstream(filename, std::ios::binary);for (int i = 0; i < BLOCKS; ++i) {file.write(buf.data(), buf.size());}auto stop = std::chrono::high_resolution_clock::now();auto costTime = (stop - start).count() / 1e9;std::cout << "write 1G奇函数定义 cost time: " << costTime << std::endl;std::cout << "speed: " << 1 / costTime << std::endl;return 0;}int diskTest1(){const int BLOCKS = 1024;const int BLOCK_SIZE = 1024 * 1024;auto filename = "F:/test.dat";auto start = std::chrono::high_resolution_clock::now();std::vector<char> buf(BLOCK_SIZE);HANDLE hfile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_WRITE | FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_F青云汇LAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,NULL);if (hfile == INVALID_HANDLE_VALUE) {std::cout << "Can't open" << filename << std::endl;return fal;}for (int i = 0; i < BLOCKS; ++i) {DWORD dwWritten;     //保存写了多少字节到文件中WriteFile(hfile, buf.data(), buf.size(), &dwWritten, 0);}CloHandle(hfile);auto stop = std::chrono::high_resolution_clock::now();auto costTime = (stop - start).count() / 1e9;std::cout << "write 1G cost time: " << costTime << std::endl;std::cout << "speed: " << 1 / costTime << std::endl;return 0;}int diskTest2(){const int BLOCKS = 1024;const int BLOCK_SIZE = 1024 * 1024;auto filename = "F:/test.dat";auto start = std::chrono::high_resolution_clock::now();std::vector<char> buf(BLOCK_SIZE);HANDLE hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHAR二年级古诗二首E_WRITE,NULL,OPEN_ALWAYS,FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,NULL);if (hFile == INVALID_HANDLE_VALUE) {return -1;}std::vector<OVERLAPPED> ols(BLOCKS);std::vector<HANDLE> events(BLOCKS);for (int i = 0; i < BLOCKS; ++i) {events[i] = CreateEvent(NULL, TRUE, FALSE, NULL);ols[i].Offt = i * buf.size();ols[i].hEvent = events[i];DWORD written = 0;BOOL rc = WriteFile(hFile, buf.data(), buf.size(), &written, &ols[i]);if (rc) {// done}el if (GetLastError() == ERROR_IO_PENDING) {// wait//WaitForSingleObject(hFile, INFINITE);//bool rc = GetOverlappedResult(hFile, &ols[i], &written, FALSE);}el {// failedreturn -1;}}//WaitForMultipleObjects(BLOCKS, events.data(), TRUE, INFINITE);for (int i = 0; i < BLOCKS; ++i) {WaitForSingleObject(&events[i], INFINITE);DWORD written = 0;bool rc = GetOverlappedResult(hFile, &ols[i], &written, FALSE);}CloHandle(hFile);auto stop = std::chrono::high_resolution_clock::now();auto costTime = (stop - start).count() / 1e9;std::cout << "write 1G cost time: " << costTime << std::endl;std::cout << "speed: " << 1 / costTime << std::endl;return 0;}int diskTest3(){const int BLOCKS = 1024;const int BLOCK_SIZE = 1024 * 1024;auto filename = "F:/test.dat";auto start = std::chrono::high_resolution_clock::now();std::vector<char> buf(BLOCK_SIZE);HANDLE hfile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE,FILE_SHARE_WRITE | FILE_SHARE_READ, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING 香港回归晚会| FILE_FLAG_WRITE_THROUGH,NULL);if (hfile == INVALID_HANDLE_VALUE) {std::cout << "Can't open" << filename << std::endl;return fal;}std::vector<OVERLAPPED> ols(BLOCKS);std::vector<HANDLE> events(BLOCKS);for (int i = 0; i < BLOCKS; ++i) {events[i] = CreateEvent(NULL, TRUE, FALSE, NULL);ols[i].hEvent = events[i];ols[i].Offt = i * buf.size();if (FALSE == WriteFileEx(hfile, buf.data(), buf.size(), &ols[i], FileIOCompletionRoutine)){CloHandle(hfile);return -1;}SleepEx(INFINITE, TRUE);}CloHandle(hfile);auto stop = std::chrono::high_resolution_clock::now();auto costTime = (stop - start).count() / 1e9;std::cout << "write 1G cost time: " << costTime << std::endl;std::cout << "speed: " << 1 / costTime << std::endl;    return 0;}

本文地址:https://blog.csdn.net/Benjaminzhou93/article/details/107856896

本文发布于:2023-04-04 02:31:19,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/efdc64dbc40ae41ffc101f7a1f5ff2ba.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:win 环境磁盘速度测试.doc

本文 PDF 下载地址:win 环境磁盘速度测试.pdf

标签:青云   写了   英语   古诗
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图