Skip to content

Instantly share code, notes, and snippets.

@brianv0
Last active August 29, 2015 14:25
Show Gist options
  • Save brianv0/d7f53df8aba7667cde1c to your computer and use it in GitHub Desktop.
Save brianv0/d7f53df8aba7667cde1c to your computer and use it in GitHub Desktop.
File benchmark
#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;
}
@brianv0
Copy link
Author

brianv0 commented Jul 24, 2015

~ 1.6 seconds for unencrypted drive, no antivirus

@brianv0
Copy link
Author

brianv0 commented Jul 24, 2015

31 seconds on 2010 MBP (spinning disk).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment