菜鸟提问:C++实现文件读写速度测试迷茫?
本人想要在嵌入式平台下测试SD卡中文件读写速度测试,设想把SD卡内的文件读或是写到一个缓冲区中buffer后丢弃,不断读写直到整个文件读写完成,计算整个过程使用的时间,文件大小已知就可以得出速度大小。本人尝试两种方法都存在问题,现把代码贴出来,希望大家给我看看那里错了,本人不胜感激!
FILE* file = NULL ;
DWORD Tick1,Tick2,Tick3,Tick4;
CHAR buf[512];
file = fopen("\\Storage Card\\10M.bin\\10M.bin", "r+t");
Tick1=GetTickCount(); // gets current time
if(file)
{
int num = 1;
while (num)
{
memset(buf,0,512);
num = fread(buf,sizeof(CHAR),512,file);
fclose( file );
Tick2=GetTickCount()-Tick1;
RETAILMSG(1,
(TEXT("shijiancha1 = %d \n"),Tick2));
}
}
本程序测试时不能实现整个文件读的。本人又模仿msdn编写下面一个,还是不行。
FILE *stream;
DWORD Tick1,Tick2,Tick3,Tick4;
char list[512];
int i, numread, numwritten;
CFile strFileR;
/* Open file in text mode:*/
if( (stream = fopen("\\Storage Card\\10M.bin", "r+t" )) != NULL )
{
Tick1=GetTickCount(); // gets current time
/* Write 512 characters to stream */
numwritten = fwrite(list, sizeof(list), strFileR.GetLength()+1, stream );
fclose( stream );
Tick2=GetTickCount()-Tick1;
RETAILMSG(1,
(TEXT("shijiancha1 = %d \n"),Tick2));
}
else
printf( "Problem opening the file\n" );
if( (stream = fopen("\\Storage Card\\10M.bin", "r+t" )) != NULL )
{
Tick4=GetTickCount(); // gets current time
/* Attempt to read in 512 characters */
numread = fread(list, sizeof(list), strFileR.GetLength()+1, stream );
RETAILMSG(1,
(TEXT("numread = %d \n"),numread));
RETAILMSG(1,
(TEXT("list = %d \n"),list));
fclose( stream );
Tick3=GetTickCount()-Tick4;
RETAILMSG(1,
(TEXT("shijiancha3 = %d \n"),Tick3));
}
else
printf( "File could not be opened\n" );
l两个程序反馈回来的和我实际设想的差距太大,结果存在明显错误,劳烦大家帮我看看,提供宝贵建议,再次感谢!
FILE* file = NULL ;
DWORD Tick1,Tick2,Tick3,Tick4;
CHAR buf[512];
file = fopen("\\Storage Card\\10M.bin\\10M.bin", "r+t");
Tick1=GetTickCount(); // gets current time
if(file)
{
int num = 1;
while (num)
{
memset(buf,0,512);
num = fread(buf,sizeof(CHAR),512,file);
fclose( file );
Tick2=GetTickCount()-Tick1;
RETAILMSG(1,
(TEXT("shijiancha1 = %d \n"),Tick2));
}
}
本程序测试时不能实现整个文件读的。本人又模仿msdn编写下面一个,还是不行。
FILE *stream;
DWORD Tick1,Tick2,Tick3,Tick4;
char list[512];
int i, numread, numwritten;
CFile strFileR;
/* Open file in text mode:*/
if( (stream = fopen("\\Storage Card\\10M.bin", "r+t" )) != NULL )
{
Tick1=GetTickCount(); // gets current time
/* Write 512 characters to stream */
numwritten = fwrite(list, sizeof(list), strFileR.GetLength()+1, stream );
fclose( stream );
Tick2=GetTickCount()-Tick1;
RETAILMSG(1,
(TEXT("shijiancha1 = %d \n"),Tick2));
}
else
printf( "Problem opening the file\n" );
if( (stream = fopen("\\Storage Card\\10M.bin", "r+t" )) != NULL )
{
Tick4=GetTickCount(); // gets current time
/* Attempt to read in 512 characters */
numread = fread(list, sizeof(list), strFileR.GetLength()+1, stream );
RETAILMSG(1,
(TEXT("numread = %d \n"),numread));
RETAILMSG(1,
(TEXT("list = %d \n"),list));
fclose( stream );
Tick3=GetTickCount()-Tick4;
RETAILMSG(1,
(TEXT("shijiancha3 = %d \n"),Tick3));
}
else
printf( "File could not be opened\n" );
l两个程序反馈回来的和我实际设想的差距太大,结果存在明显错误,劳烦大家帮我看看,提供宝贵建议,再次感谢!
...全文
相关推荐
C++菜鸟必读
【C++菜鸟必读】这篇文章主要讲解了一些与电脑性能优化和C++编程语言无关的技巧,但对初学者了解电脑维护很有帮助。以下是对描述中提到的几点进行详细解释:1.
非常好的C#菜鸟基础教程
以下是一些关键知识点的详细说明:1. **C#语法**:C#的语法与C++和Java有许多相似之处,但也有其独特之处。
C++实现KNN文本分类算法.docx
在C++中实现KNN文本分类算法前,需要完成以下准备工作:1. 定义训练集和测试集:训练集用于模型的构建,测试集用于模型的验证和测试。
菜鸟初学在vc下编译x264详解.pdf
**Visual C++ 6.0 Processor Pack**:支持多处理器编译,加快编译速度。4.
MATLAB初学者教程 MATLAB编程-菜鸟入门(清晰版)
- **测试验证**:对程序进行单元测试和综合测试,确保每一个部分都能正常工作。- **函数的使用与模块化编程**:强调使用函数来封装逻辑,实现模块化编程。


