From 4ef69136795c5ce2f422e292675a46af7b2a7f8e Mon Sep 17 00:00:00 2001 From: pmf Date: Tue, 12 Aug 2008 15:40:30 +0000 Subject: [PATCH] add buffering to java test progs git-svn-id: http://ltt.polymtl.ca/svn@3002 04897980-b3bd-0310-b5e0-8ef037075253 --- trunk/masters-pmf/java_speed_test/c/main.c | 45 +++++++------------ .../java_speed_test/java/read_trace.java | 3 +- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/trunk/masters-pmf/java_speed_test/c/main.c b/trunk/masters-pmf/java_speed_test/c/main.c index a45fc7bd..08baaf62 100644 --- a/trunk/masters-pmf/java_speed_test/c/main.c +++ b/trunk/masters-pmf/java_speed_test/c/main.c @@ -1,3 +1,6 @@ +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 + #include #include #include @@ -10,15 +13,15 @@ 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, ×tamp, 4); - if(result == 0) + fscanf(fp, "%4c", ×tamp); + 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; } diff --git a/trunk/masters-pmf/java_speed_test/java/read_trace.java b/trunk/masters-pmf/java_speed_test/java/read_trace.java index 99cab41d..91f48fd5 100644 --- a/trunk/masters-pmf/java_speed_test/java/read_trace.java +++ b/trunk/masters-pmf/java_speed_test/java/read_trace.java @@ -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; -- 2.34.1