add buffering to java test progs
authorpmf <pmf@04897980-b3bd-0310-b5e0-8ef037075253>
Tue, 12 Aug 2008 15:40:30 +0000 (15:40 +0000)
committerpmf <pmf@04897980-b3bd-0310-b5e0-8ef037075253>
Tue, 12 Aug 2008 15:40:30 +0000 (15:40 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@3002 04897980-b3bd-0310-b5e0-8ef037075253

trunk/masters-pmf/java_speed_test/c/main.c
trunk/masters-pmf/java_speed_test/java/read_trace.java

index a45fc7bd4120e3d825b5a28d630e96a8efd6ada3..08baaf62b78b76cca7f6da8c5a2318fb135735c4 100644 (file)
@@ -1,3 +1,6 @@
+#define _LARGEFILE_SOURCE
+#define _FILE_OFFSET_BITS 64
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 int main(int argc, char **argv)
 {
        int result;
-       int fd;
+       FILE *fp;
        int print = 0;
 
        if(argc >= 2 && !strcmp(argv[1], "-p"))
                print = 1;
 
-       result = fd = open("../trace.dat", O_RDONLY);
-       if(result == -1) {
-               perror("open");
+       fp = fopen("../trace.dat", "r");
+       if(fp == NULL) {
+               perror("fopen");
                return 1;
        }
 
@@ -28,33 +31,18 @@ int main(int argc, char **argv)
                unsigned char arglen;
                char *args;
 
-               result = read(fd, &timestamp, 4);
-               if(result == 0)
+               fscanf(fp, "%4c", &timestamp);
+               if(feof(fp))
                        break;
-               if(result < 4) {
-                       perror("read");
-                       return 1;
-               }
-
-               result = read(fd, &id, 2);
-               if(result < 2) {
-                       perror("read");
-                       return 1;
-               }
-
-               result = read(fd, &arglen, 1);
-               if(result < 1) {
-                       perror("read");
-                       return 1;
-               }
+
+               fscanf(fp, "%2c", &id);
+
+               fscanf(fp, "%1c", &arglen);
 
                args = malloc(arglen);
 
-               result = read(fd, args, arglen);
-               if(result < arglen) {
-                       perror("read");
-                       return 1;
-               }
+               // manually specify length of args
+               fscanf(fp, "%15c", args);
 
                unsigned short arg1;
                char *arg2;
@@ -66,8 +54,9 @@ int main(int argc, char **argv)
                        printf("timestamp %lu id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2);
 
                free(args);
+
        }
-       close(fd);
+       fclose(fp);
 
        return 0;
 }
index 99cab41dc772451efe4aed1b073914513fd05916..91f48fd5cc7c19bc8c54f4ef9fdf99126d2dc468 100644 (file)
@@ -6,7 +6,8 @@ public class read_trace {
 
                try {
                        FileInputStream file_input = new FileInputStream ("../trace.dat");
-                       DataInputStream data_input = new DataInputStream (file_input);
+                       BufferedInputStream buffered_input = new BufferedInputStream(file_input);
+                       DataInputStream data_input = new DataInputStream (buffered_input);
                        
                        int timestamp;
                        short id;
This page took 0.025502 seconds and 4 git commands to generate.