Skip to content

Commit

Permalink
Merge pull request #2 from dev
Browse files Browse the repository at this point in the history
Optimized the tests and made them more accurate
  • Loading branch information
ViktorPopp authored Jan 4, 2025
2 parents d387f5e + 3046c5d commit 0c20905
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
14 changes: 11 additions & 3 deletions DiskUtilityCLI/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ bool Application::promptIterationCount(int& iterationCount) {

void Application::performDiskTests(const std::string& diskLetter, size_t dataSizeMB, bool useCaching, int iterationCount) {
const size_t dataSizeBytes = dataSizeMB * 1024 * 1024;
std::vector<char> buffer(1024 * 1024, '\0');
std::vector<char> buffer(1024 * 1024 * 4, '\0');
std::string filePath = diskLetter + ":\\DiskUtilsTestFile.dat";

std::vector<double> writeSpeeds, readSpeeds;

// Warm-up runs
for (int i = 0; i < 2; ++i) {
std::cout << "\nWarm-up run " << i + 1 << "\n";
testWriteSpeed(filePath, buffer, dataSizeMB, useCaching);
testReadSpeed(filePath, buffer, dataSizeMB, useCaching);
cleanUpTestFile(filePath);
}

for (int iteration = 1; iteration <= iterationCount; ++iteration) {
std::cout << "\nIteration " << iteration << ":\n";

Expand All @@ -118,7 +126,6 @@ void Application::performDiskTests(const std::string& diskLetter, size_t dataSiz
displayFinalResults(writeSpeeds, readSpeeds);
}


double Application::testWriteSpeed(const std::string& filePath, std::vector<char>& buffer, size_t dataSizeMB, bool useCaching) {
HANDLE hFile = CreateFileA(
filePath.c_str(),
Expand All @@ -139,7 +146,7 @@ double Application::testWriteSpeed(const std::string& filePath, std::vector<char
auto start = std::chrono::high_resolution_clock::now();

size_t bufferSize = buffer.size();
for (size_t i = 0; i < dataSizeMB; ++i) {
for (size_t i = 0; i < dataSizeMB * 1024 / (bufferSize / 1024); ++i) {
DWORD bytesWritten;
if (!WriteFile(hFile, buffer.data(), bufferSize, &bytesWritten, NULL) || bytesWritten != bufferSize) {
std::cerr << "Error: WriteFile failed. " << std::system_category().message(GetLastError()) << std::endl;
Expand All @@ -148,6 +155,7 @@ double Application::testWriteSpeed(const std::string& filePath, std::vector<char
}
}

FlushFileBuffers(hFile); // Ensure data is written to disk
auto end = std::chrono::high_resolution_clock::now();
CloseHandle(hFile);

Expand Down
20 changes: 12 additions & 8 deletions DiskUtilityCLI/DiskUtilityCLI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,24 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)Build\Binraries</OutDir>
<IntDir>$(SolutionDir)Build\Objects</IntDir>
<OutDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Binraries\</OutDir>
<IntDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Objects\</IntDir>
<TargetName>diskutil</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)Build\Binraries</OutDir>
<IntDir>$(SolutionDir)Build\Objects</IntDir>
<OutDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Binraries\</OutDir>
<IntDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Objects\</IntDir>
<TargetName>diskutil</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)Build\Binraries</OutDir>
<IntDir>$(SolutionDir)Build\Objects</IntDir>
<OutDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Binraries\</OutDir>
<IntDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Objects\</IntDir>
<TargetName>diskutil</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)Build\Binraries</OutDir>
<IntDir>$(SolutionDir)Build\Objects</IntDir>
<OutDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Binraries\</OutDir>
<IntDir>$(SolutionDir)Build\$(Configuration)-$(Platform)\Objects\</IntDir>
<TargetName>diskutil</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down

0 comments on commit 0c20905

Please sign in to comment.