Systémové programovanie domáca č. 4 - riesenie
Created: 2010-04-25 - 10:45
Prve - vysokourovnove kopirovanie
#include
int main() {
int i = 0;
while(++i<100){
int z;
FILE *in,*out;
in = fopen("input","r");
out = fopen("output","w");
char c;
while((c=fgetc(in))!=EOF){
fputc(c,out);
}
}
}
time ./prva >> vysledok
real 0m11.504s
user 0m9.973s
sys 0m1.527s
Druhe - nizkourovnove po byteoch, muhehe :D
#include
#include
#include
int main() {
int i = 0;
while(++i<100){
char c;
int in,out;
in = open("input",O_RDONLY);
out = open("output",O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
while(read(in,&c,1)==1){
write(out,&c,1);
}
}
}
time ./druha
^C //// stopnute po 4 minutach, extremne dlho by to trvalo
real 4m53.539s
user 0m23.571s
sys 4m29.646s
tretia - mapovanie do pamate
#include
#include
#include
#include
#include
#include
#define DLZKA_SUBORU 0x800
int main() {
int i = 0;
while(++i<100){
int fd;
void* subor_v_pamati;
fd = open("output", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
lseek(fd, DLZKA_SUBORU+1, SEEK_SET);
write(fd, "", 1);
lseek(fd, 0, SEEK_SET);
subor_v_pamati = mmap(0, DLZKA_SUBORU, PROT_WRITE, MAP_SHARED, fd, 0);
FILE *in;
in = fopen("input","r");
char c;
while((c=fgetc(in))!=EOF){
sprintf((char*)subor_v_pamati,"%c",c);
}
munmap(subor_v_pamati, DLZKA_SUBORU);
}
}
time ./tretia
real 0m48.298s
user 0m48.138s
sys 0m0.151s