#include #include #include #include #include #include #include static inline double getdtime(void) { struct timeval tv; gettimeofday(&tv, NULL); return (double)tv.tv_sec + (double)tv.tv_usec * 0.001 * 0.001; } int main(int argc, char * argv[]) { char *buf_in, *buf_out; unsigned long size_in, size_out; int fd; double d_start, d_end, d_compress; if (argc != 3) { printf("./command \n"); exit(1); } d_compress = 0; // buffer for input data size_in = atoi(argv[1]); buf_in = (char *)malloc(size_in); if (!buf_in) { printf("malloc failed. %n byten", size_in); exit(1); } // buffer for output data size_out = compressBound(size_in); buf_out = (char *)malloc(size_out); if (!buf_out) { printf("malloc failed. %n byten", size_out); exit(1); } if ((fd = open(argv[2], O_RDONLY)) == 0) { printf("file open failed. %s\n", argv[2]); exit(1); } while (read(fd, buf_in, size_in)) { d_start = getdtime(); compress2(buf_out, &size_out, buf_in, size_in, Z_BEST_SPEED); d_end = getdtime(); d_compress += d_end - d_start; } printf("TOTAL COMPRESSION TIME: %lf\n", d_compress); return 0; }