#include <iostream>
#include <fstream>
#include <chrono>
void measure_read_write_speed(const std::string& file_path) {
const size_t buffer_size = 1024 * 1024; // 1MB
char* buffer = new char[buffer_size];
// Zeitmessung für Schreiboperation
auto start = std::chrono::high_resolution_clock::now();
std:
fstream ofs(file_path, std::ios::binary);
for (size_t i = 0; i < 4096; ++i) {
ofs.write(buffer, buffer_size);
}
ofs.close();
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> write_duration = end - start;
std::cout << "Schreibgeschwindigkeit: " << (4096* buffer_size) / (1024 * 1024 * write_duration.count()) << " MB/s\n";
// Zeitmessung für Leseoperation
start = std::chrono::high_resolution_clock::now();
std::ifstream ifs(file_path, std::ios::binary);
for (size_t i = 0; i < 4096; ++i) {
ifs.read(buffer, buffer_size);
}
ifs.close();
end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> read_duration = end - start;
std::cout << "Lesegeschwindigkeit: " << (4096 * buffer_size) / (1024 * 1024 * read_duration.count()) << " MB/s\n";
delete[] buffer;
}
int main() {
measure_read_write_speed("testfile.dat");
return 0;
}