On this page i make a little programming test for IO disk programming.
For this discussion i have create a program the source of this program are below:
This test make this result:
Test Disk with buffer 512 and value in seconds 1.2308410
Test Disk with buffer 512 and value in seconds 1.1985730
Test Disk with buffer 512 and value in seconds 1.2086830
Test Disk with buffer 513 and value in seconds 1.3172980
Test Disk with buffer 513 and value in seconds 1.3090760
Test Disk with buffer 513 and value in seconds 1.3268260
Test Disk with buffer 4096 and value in seconds 1.0285520
Test Disk with buffer 4096 and value in seconds 1.0692790
Test Disk with buffer 4096 and value in seconds 1.0283970
Test Disk with buffer 4097 and value in seconds 1.2473690
Test Disk with buffer 4097 and value in seconds 1.2862490
Test Disk with buffer 4097 and value in seconds 1.2860620
From this test the size of buffer used are very important, if the buffersize is odd the performance of disk decrease, this because the filesystem block size is 4096 and odd value generate a seek move of disk head.
I exceute the test with a file size 218 MB.
For this discussion i have create a program the source of this program are below:
/*
* File: newmain.c
* Author: marco
*
* Created on 14 giugno 2008, 9.00
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
/*
*
*/
#define TDIFF(t0,t1) ((t1.tv_sec - t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec)
double disktest( const int bufferrsize);
int main(int argc, char** argv) {
//Simple program to test the disk performance
//this program access tu disk on different size of buffer
disktest(512);
disktest(512);
disktest(512);
disktest(513);
disktest(513);
disktest(513);
disktest(4096);
disktest(4096);
disktest(4096);
disktest(4097);
disktest(4097);
disktest(4097);
return (EXIT_SUCCESS);
}
double disktest( const int bufferrsize){
//Time value
struct timeval tv1,tv2;
//Reads Byte
int readbyte = 0;
//Cerate a Buffer
char buffer[bufferrsize];
//Copy file a on file b
FILE *a;
FILE *b;
//open
a = fopen("filea","rb");
b = fopen("fileb","wb");
//Controll if file open fails
if (a!=NULL&&b!=NULL){
gettimeofday(&tv1, NULL);
//Read a buffer of byte
readbyte = fread(buffer,sizeof(char),bufferrsize,a);
while(readbyte==bufferrsize){
//Copy to b
fwrite(buffer,sizeof(char),bufferrsize,b);
//read again
readbyte = fread(buffer,sizeof(char),bufferrsize,a);
}
if (readbyte>0){
//Copy to b
fwrite(buffer,sizeof(char),readbyte,b);
}
fclose(a);
fclose(b);
gettimeofday(&tv2, NULL);
long milliseconds = TDIFF(tv1, tv2);
double result;
result = ((double)milliseconds/(double)1000000);
printf("Test Disk with buffer %d and value in seconds\t\t%1.7f\n",bufferrsize,result);
return result;
}else{
printf("Io Error");
return -1;
}
}
This test make this result:
Test Disk with buffer 512 and value in seconds 1.2308410
Test Disk with buffer 512 and value in seconds 1.1985730
Test Disk with buffer 512 and value in seconds 1.2086830
Test Disk with buffer 513 and value in seconds 1.3172980
Test Disk with buffer 513 and value in seconds 1.3090760
Test Disk with buffer 513 and value in seconds 1.3268260
Test Disk with buffer 4096 and value in seconds 1.0285520
Test Disk with buffer 4096 and value in seconds 1.0692790
Test Disk with buffer 4096 and value in seconds 1.0283970
Test Disk with buffer 4097 and value in seconds 1.2473690
Test Disk with buffer 4097 and value in seconds 1.2862490
Test Disk with buffer 4097 and value in seconds 1.2860620
From this test the size of buffer used are very important, if the buffersize is odd the performance of disk decrease, this because the filesystem block size is 4096 and odd value generate a seek move of disk head.
I exceute the test with a file size 218 MB.

Calendar



