Last active
August 29, 2015 14:25
-
-
Save brianv0/d7f53df8aba7667cde1c to your computer and use it in GitHub Desktop.
File benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "stdlib.h" | |
void initBuffer(char *buffer, int bufSize){ | |
if (buffer==NULL) exit (1); | |
for (int n=0; n<bufSize; n++){ | |
buffer[n]=rand()%26+'a'; | |
} | |
} | |
int main(){ | |
char *buffer; | |
int bufSize = 4096000; | |
int bufStart = 0; | |
int fileCount = 1000; | |
int writeSize = 0; // size, in bytes, of each entry | |
long maxFileSize = 2048000; // total file size | |
int minFileSize = (int) (maxFileSize * .75); | |
buffer = (char*) malloc(bufSize); | |
initBuffer(buffer, bufSize); | |
int maxStart = bufSize - maxFileSize; | |
for(int fileIter = 0; fileIter < fileCount; fileIter++){ | |
FILE *wFile; | |
char fileName[30]; | |
sprintf(fileName, "myfile-%d.log", fileIter); | |
wFile = fopen(fileName,"w"); | |
writeSize = minFileSize + (rand() % (maxFileSize - minFileSize)); | |
bufStart = rand() % maxStart; | |
fwrite(buffer+bufStart, sizeof(char), writeSize, wFile); | |
fclose (wFile); | |
} | |
free(buffer); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
31 seconds on 2010 MBP (spinning disk).