Pastebin

Paste #24949: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main() {
    int iteration = 0;
    time_t start_time = time(NULL);
    time_t last_print_time = start_time;
    while (1) {
        // Create the file
        char filename[20];
        sprintf(filename, "file_%d", iteration);
        FILE* file = fopen(filename, "wb");
        if (file == NULL) {
            printf("Error creating file %s\n", filename);
            return 1;
        }

        // Write 6400000 random bytes to the file
        char data[6400000];
        for (int i = 0; i < 6400000; i++) {
            data[i] = rand() % 256;
        }
        fwrite(data, sizeof(char), 6400000, file);
        fclose(file);

        // Delete the file
        int result = remove(filename);
        if (result != 0) {
            printf("Error deleting file %s\n", filename);
            return 1;
        }

        // Increment the iteration number
        iteration++;

        // Calculate the number of iterations per second
        time_t current_time = time(NULL);
        double elapsed_time = difftime(current_time, start_time);
        double iterations_per_second = (double)iteration / elapsed_time;

        // Print statistics every 10 seconds
        if (difftime(current_time, last_print_time) >= 10) {
            printf("Iterations per second: %.2f\n", iterations_per_second);
            last_print_time = current_time;
        }
    }
    return 0;
}

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.