From: pmf Date: Thu, 7 Aug 2008 21:33:55 +0000 (+0000) Subject: add java speed test X-Git-Tag: v0.12.20~496 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f65716cff67a144956e4f4b1930d43e3d897e19d;p=lttv.git add java speed test git-svn-id: http://ltt.polymtl.ca/svn@2993 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/trunk/masters-pmf/java_speed_test/basic_record.dat b/trunk/masters-pmf/java_speed_test/basic_record.dat new file mode 100644 index 00000000..93b5f357 Binary files /dev/null and b/trunk/masters-pmf/java_speed_test/basic_record.dat differ diff --git a/trunk/masters-pmf/java_speed_test/bench/bench.py b/trunk/masters-pmf/java_speed_test/bench/bench.py new file mode 100644 index 00000000..b83fd558 --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/bench/bench.py @@ -0,0 +1,119 @@ +runs=10 + +class Task: + name = "unnamed" + pre_cmd = "" + cmd = "" + post_cmd = "" + results = 0 + remain = 10 + + def __init__(self): + self.results = [] + +tasks = [] + +t1 = Task() +t1.name = "C version (without print)" +t1.pre_cmd = "" +t1.cmd = "pushd ../c >/dev/null; ./main; popd >/dev/null;" +t1.post_cmd = "" +tasks.append(t1) + +t3 = Task() +t3.name = "C version (with print)" +t3.pre_cmd = "" +t3.cmd = "pushd ../c >/dev/null; ./main -p; popd >/dev/null;" +t3.post_cmd = "" +tasks.append(t3) + +t5 = Task() +t5.name = "C version (with print, but sent to /dev/null)" +t5.pre_cmd = "" +t5.cmd = "pushd ../c >/dev/null; ./main -p >/dev/null; popd >/dev/null;" +t5.post_cmd = "" +tasks.append(t5) + +t2 = Task() +t2.name = "Java version (without print)" +t2.pre_cmd = "" +t2.cmd = "pushd ../java >/dev/null; java read_trace; popd >/dev/null;" +t2.post_cmd = "" +tasks.append(t2) + +t4 = Task() +t4.name = "Java version (with print)" +t4.pre_cmd = "" +t4.cmd = "pushd ../java >/dev/null; java read_trace -p; popd >/dev/null;" +t4.post_cmd = "" +tasks.append(t4) + +t6 = Task() +t6.name = "Java version (with print, but sent to /dev/null)" +t6.pre_cmd = "" +t6.cmd = "pushd ../java >/dev/null; java read_trace -p >/dev/null; popd >/dev/null;" +t6.post_cmd = "" +tasks.append(t6) + +import os +import time + +def average(lst): + sum = 0 + count = 0 + + for i in lst: + sum += i + count += 1 + + if count == 0: + return 0 + else: + return sum/count + +def min(lst): + if len(lst) == 0: + return 0 + + found = lst[0] + + for i in lst: + if i < found: + found = i + + return found + +def max(lst): + if len(lst) == 0: + return 0 + + found = lst[0] + + for i in lst: + if i > found: + found = i + + return found + +def main(): + for task in tasks: + while task.remain > 0: + os.system(task.pre_cmd) + t_start = time.time() + os.system(task.cmd) + t_end = time.time() + os.system(task.post_cmd) + task.remain-=1 + task.results.append(t_end-t_start) + print(task.results) + + print "------------------------------------" + for task in tasks: + print "RESULTS for " + task.name + print "Runs: " + str(len(task.results)) + print "Average: " + str(round(average(task.results), 3)) + print "Min: " + str(round(min(task.results), 3)) + print "Max: " + str(round(max(task.results), 3)) + print "" + +main() diff --git a/trunk/masters-pmf/java_speed_test/c/Makefile b/trunk/masters-pmf/java_speed_test/c/Makefile new file mode 100644 index 00000000..f0035b54 --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/c/Makefile @@ -0,0 +1,5 @@ +main: main.c + gcc -o main -O3 main.c + +clean: + rm main diff --git a/trunk/masters-pmf/java_speed_test/c/main.c b/trunk/masters-pmf/java_speed_test/c/main.c new file mode 100644 index 00000000..e7bac623 --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/c/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#include +#include + +int main() +{ + int result; + int fd; + + result = fd = open("../trace.dat", O_RDONLY); + if(result == -1) { + perror("open"); + return 1; + } + + while(1) { + unsigned long timestamp; + unsigned short id; + unsigned char arglen; + char *args; + + result = read(fd, ×tamp, 4); + if(result == 0) + 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; + } + + args = malloc(arglen); + + result = read(fd, args, arglen); + if(result < arglen) { + perror("read"); + return 1; + } + + unsigned short arg1; + char *arg2; + + arg1 = *(unsigned short *)args; + arg2 = args+2; + + printf("timestamp %u id %hu args=(arg1=%hu arg2=\"%s\")\n", timestamp, id, arg1, arg2); + + free(args); + } + close(fd); + + return 0; +} diff --git a/trunk/masters-pmf/java_speed_test/java/Makefile b/trunk/masters-pmf/java_speed_test/java/Makefile new file mode 100644 index 00000000..3bc3f132 --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/java/Makefile @@ -0,0 +1,2 @@ +read_trace.class: read_trace.java + javac -source 1.5 read_trace.java diff --git a/trunk/masters-pmf/java_speed_test/java/read_trace.java b/trunk/masters-pmf/java_speed_test/java/read_trace.java new file mode 100644 index 00000000..80a3bc17 --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/java/read_trace.java @@ -0,0 +1,53 @@ +import java.io.*; + +public class read_trace { + public static void main(String[] args) { + int tmp = 0; + + try { + FileInputStream file_input = new FileInputStream ("../trace.dat"); + DataInputStream data_input = new DataInputStream (file_input); + + int timestamp; + short id; + byte length; + + while(true) { + timestamp = data_input.readInt(); + id = data_input.readShort(); + length = data_input.readByte(); + + byte[] buf = new byte[length]; + data_input.readFully(buf, 0, length); + + + ByteArrayInputStream eargs = new ByteArrayInputStream(buf); + DataInputStream eargs_data = new DataInputStream (eargs); + + /* read arg 1 (short) */ + short arg1 = eargs_data.readShort(); + + /* read arg 2 (string) */ + eargs_data.mark(10000); + int strlen=0; + while(eargs_data.readByte() != 0) + strlen++; + eargs_data.reset(); + byte[] arg2 = new byte[strlen]; + eargs_data.readFully(arg2, 0, strlen); + + //System.out.printf("timestamp %d id %d args=(short=%d string=\"%s\") %n", timestamp, id, arg1, new String(arg2)); + String strout = String.format("timestamp %d id %d args=(short=%d string=\"%s\") %n", timestamp, id, arg1, new String(arg2)); + tmp += strout.length(); + } + + } + catch(IOException e) { + //System.out.println ("IO exception = " + e ); + //e.printStackTrace(); + } + + //file_input.close(); + System.out.println(tmp); + } +} diff --git a/trunk/masters-pmf/java_speed_test/make_trace.sh b/trunk/masters-pmf/java_speed_test/make_trace.sh new file mode 100644 index 00000000..53e7217c --- /dev/null +++ b/trunk/masters-pmf/java_speed_test/make_trace.sh @@ -0,0 +1,2 @@ +(for i in $(seq 1000); do cat basic_record.dat; done) >tmp.dat +(for i in $(seq 10); do cat tmp.dat; done) >trace.dat