📜 ⬆️ ⬇️

Flash drive speed

Hello dear iron lovers!

Problem


It is impossible to find information about the speed of a specific USB flash drive model (in the common flash drive) on the network. The reason for the secrecy of this information is not known to me.

Our solution


A utility was developed for testing flash drives and sending results to the site.
image

')

Benchmark


The application is written in the .NET Framework 2.0. For low-level operations, a .dll module is written in C ++.
The goal was to evaluate the speed of reading and writing to the card blocks of different sizes. To solve this problem, I used WinAPI functions: CreateFile, WriteFile and ReadFile. When creating the file, the FILE_FLAG_NO_BUFFERING flag was set, which indicates to the OS that all sorts of file caches should not be used.
Here is the test for writing blocks:
__declspec(dllexport) double WriteBench(LPCSTR path, long size, long count, char * ErrorMessage)
{
HRTimer timer; int i;
double elapsed;
HANDLE hFile; DWORD dwResult;
void * buffer = malloc(size);
memset(buffer, -1, size);
hFile = CreateFileA(path,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING,
NULL);

if (hFile == INVALID_HANDLE_VALUE)
{
sprintf(( char *)ErrorMessage, "Could not open file (error %d)\n" , GetLastError());
return 0;
}

timer.StartTimer();
for (i =0 ; i< count; i++){
if (!WriteFile(hFile, buffer, size, &dwResult, NULL))
{
sprintf(( char *)ErrorMessage, "Could not write to file (error %d)\n" , GetLastError());
return 0;
}
}
elapsed = timer.StopTimer();

CloseHandle(hFile);
DeleteFileA(path);
free(buffer);
return elapsed;
}


* This source code was highlighted with Source Code Highlighter .


I would be very grateful if you look at my project UsbFlashSpeed.com and point out the flaws found.
This is a post for preliminary testing of the service and collecting critical comments! Announcement of the service will be later.

Source: https://habr.com/ru/post/95384/


All Articles