Skip to content

Instantly share code, notes, and snippets.

@brianv0
Created July 24, 2015 19:22
Show Gist options
  • Save brianv0/bbe1a7905d565da2c86f to your computer and use it in GitHub Desktop.
Save brianv0/bbe1a7905d565da2c86f to your computer and use it in GitHub Desktop.
Write-Ahead log simulated benchmark
#include "stdio.h"
#include "stdlib.h"
void initBuffer(char *buffer){
if (buffer==NULL) exit (1);
for (int n=0; n<16000; n++){
buffer[n]=rand()%26+'a';
}
}
int main(){
char *buffer;
int count = 0;
int previous = 0;
int bufStart = 0;
FILE *wFile;
int writeSize = 0; // size, in bytes, of each entry
long fileSize = 500000000; // total file size
long total = 0; // total bytes written (~fileSize)
int flushSize = 32000; // number bytes written before we force flush
wFile = fopen("myfile.log","w");
buffer = (char*) malloc (16000);
initBuffer(buffer);
while (total < fileSize){
writeSize = 1500 + rand() % 5500;
bufStart = rand() % 8000;
size_t written = fwrite(buffer+bufStart, sizeof(char), writeSize, wFile);
total += written;
count++;
if((total - previous) > flushSize){
fwrite("\n", sizeof(char), 1, wFile);
fflush(wFile);
previous = total;
}
}
printf("Total number of entries forced to disk: %d\n", count);
fclose (wFile);
free(buffer);
return 0;
}
@brianv0
Copy link
Author

brianv0 commented Jul 24, 2015

2010 Macbook Pro:
Total number of entries forced to disk: 117952

real 0m8.012s
user 0m0.128s
sys 0m1.506s

~15k entries per second

2015 Macbook pro
Total number of entries forced to disk: 2353177

real 0m11.768s
user 0m1.293s
sys 0m10.374s

~200k entries per second

@brianv0
Copy link
Author

brianv0 commented Jul 27, 2015

With Anti-Virus:

bvan@dhcp-visitor-220-197:scratch$ time ./a.out
Total number of entries forced to disk: 2353177

real 0m12.049s
user 0m1.287s
sys 0m10.714s
bvan@dhcp-visitor-220-197:scratch$ time ./a.out
Total number of entries forced to disk: 2353177

real 0m12.494s
user 0m1.282s
sys 0m11.104s
bvan@dhcp-visitor-220-197:scratch$ time ./a.out
Total number of entries forced to disk: 2353177

real 0m12.525s
user 0m1.340s
sys 0m11.077s

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