diff --git a/src/main/Test.java b/src/main/Test.java index ae3859da231a6c4683fd4e040e438d93c55f2d5e..0321d8473b0f2c57ccc1781a859ae33426fe5bfa 100644 --- a/src/main/Test.java +++ b/src/main/Test.java @@ -32,9 +32,9 @@ public class Test { } public static void main(String[] args) throws InterruptedException { - int listInitialSize = 100;// Integer.parseInt(args[0]); - int listCapacity = 300000;// Integer.parseInt(args[1]); - int numberThreads = 12;// Integer.parseInt(args[2]); + int listInitialSize = Integer.parseInt(args[0]); + int listCapacity = Integer.parseInt(args[1]); + int numberThreads = Integer.parseInt(args[2]); RandomNumbers.MAX = listCapacity; diff --git a/test/CoarseListThroughput.pdf b/test/CoarseListThroughput.pdf new file mode 100644 index 0000000000000000000000000000000000000000..361592c35f71f133a617f5bb6fea7fb207391fb8 Binary files /dev/null and b/test/CoarseListThroughput.pdf differ diff --git a/test/analyse-results.py b/test/analyse-results.py deleted file mode 100644 index 7359337a1c5ecb08713c5dfc7125a4694c4a2186..0000000000000000000000000000000000000000 --- a/test/analyse-results.py +++ /dev/null @@ -1,210 +0,0 @@ -import os -import numpy as np -import matplotlib.pyplot as plt -import matplotlib as mpl - -output_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output") -colors = [ - "#5b9bd5", - "#ed7d31", - "#a4a4a4", - "#fdc131", - "#99731a", - "#70ad46", -] -patterns = [ - "/", - "o", - "x", -] - - -def get_result_from_line(line): - return line.split(":")[1].strip() - - -def output_file_2_dict(file): - d = {} - with open(file, "r") as lines: - for line in lines: - if line.startswith("Initial list size"): - d["initial_size"] = int(get_result_from_line(line)) - elif line.startswith("Maximum list size"): - d["maximum_size"] = int(get_result_from_line(line)) - elif line.startswith("Use warm-up"): - d["warm_up"] = get_result_from_line(line) == "true" - elif line.startswith("Number of producers"): - d["producers"] = int(get_result_from_line(line)) - elif line.startswith("Number of consumers"): - d["consumers"] = int(get_result_from_line(line)) - elif line.startswith("Current monitor size"): - d["final_monitor_size"] = int(get_result_from_line(line)) - elif line.startswith("Number of enqueues"): - d["enqueues"] = int(get_result_from_line(line)) - elif line.startswith("Number of dequeues"): - d["dequeues"] = int(get_result_from_line(line)) - return d - - -def output_2_dict(): - data = [] - for f in os.listdir(output_folder): - if not f.endswith(".txt"): - continue - data.append(output_file_2_dict(os.path.join(output_folder, f))) - return data - - -def get_enq_deq_plot( - ax, labels, index, width, enqueues, dequeues, legend_label, current_values -): - offset = (width * index) + (0.01 * index) - sum_enq_deq = np.add(enqueues, dequeues) - avg_enq = np.divide(enqueues, sum_enq_deq) - avg_deq = np.divide(dequeues, sum_enq_deq) - rects_enq = ax.bar( - labels + offset, - enqueues, - width, - label=f"{legend_label} - enq.", - edgecolor=("white"), - color=colors[index], - hatch=patterns[index], - ) - rects_deq = ax.bar( - labels + offset, - dequeues, - width, - bottom=enqueues, - label=f"{legend_label} - deq.", - edgecolor=("white"), - color=colors[3 + index], - hatch=patterns[index], - ) - auto_label(rects_enq, ax, avg_enq, current_values, True) - auto_label(rects_deq, ax, avg_deq) - - -def get_subplot(ax, data, title): - ax.set_title(title) - width = 0.3 - labels = np.arange(3) - data_per_initial_sizes = [ - [x for x in data if x["maximum_size"] == 300000], - [x for x in data if x["maximum_size"] == 500000], - [x for x in data if x["maximum_size"] == 1000000], - ] - maximum_300000_enq = [x["enqueues"] for x in data_per_initial_sizes[0]] - maximum_300000_deq = [x["dequeues"] for x in data_per_initial_sizes[0]] - maximum_300000_current = [ - x["final_monitor_size"] for x in data_per_initial_sizes[0] - ] - maximum_500000_enq = [x["enqueues"] for x in data_per_initial_sizes[1]] - maximum_500000_deq = [x["dequeues"] for x in data_per_initial_sizes[1]] - maximum_500000_current = [ - x["final_monitor_size"] for x in data_per_initial_sizes[1] - ] - maximum_1000000_enq = [x["enqueues"] for x in data_per_initial_sizes[2]] - maximum_1000000_deq = [x["dequeues"] for x in data_per_initial_sizes[2]] - maximum_1000000_current = [ - x["final_monitor_size"] for x in data_per_initial_sizes[2] - ] - - get_enq_deq_plot( - ax, - labels, - 0, - width, - maximum_300000_enq, - maximum_300000_deq, - "Max. 300k", - maximum_300000_current, - ) - get_enq_deq_plot( - ax, - labels, - 1, - width, - maximum_500000_enq, - maximum_500000_deq, - "Max. 500k", - maximum_500000_current, - ) - get_enq_deq_plot( - ax, - labels, - 2, - width, - maximum_1000000_enq, - maximum_1000000_deq, - "Max. 1M", - maximum_1000000_current, - ) - - ax.set_yticks([0, np.max(np.add(maximum_300000_enq, maximum_300000_deq))]) - ax.set_xticks(labels + width + 0.01) - ax.set_xticklabels([100000, 200000, 300000]) - ax.legend(loc="upper right") - - -def auto_label(rects, ax, percentages, current_values=[], bottom=False): - for i, rect in enumerate(rects): - rect.set_alpha(0.7) - height = rect.get_height() - ax.annotate( - "{0:.1f}%".format(percentages[i] * 100) + f"\n{height}", - xy=(0, 0), - xytext=( - (rect.get_x() + rect.get_width() / 2), - height / 2 if bottom else (height + height / 2), - ), - textcoords="data", - ha="center", - va="center", - fontweight="bold", - ) - if bottom: - ax.annotate( - "{}".format(current_values[i]), - xy=(0, 0), - xytext=((rect.get_x() + rect.get_width() / 2), height + height,), - textcoords="data", - ha="center", - va="bottom", - fontweight="bold", - ) - - -def get_plot(data, used_warm_up, output_file): - data_sorted = sorted( - data, - key=lambda x: ( - x["initial_size"], - x["maximum_size"], - x["producers"], - x["consumers"], - ), - ) - plots_data = [ - [x for x in data_sorted if x["producers"] == 1 and x["consumers"] == 11], - [x for x in data_sorted if x["producers"] == 4 and x["consumers"] == 8], - [x for x in data_sorted if x["producers"] == 8 and x["consumers"] == 4], - [x for x in data_sorted if x["producers"] == 11 and x["consumers"] == 1], - ] - fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(28, 24)) - # fig.tight_layout() - warm_up_tile = ", with warm-up" if used_warm_up else ", without warm-up" - get_subplot(ax[0, 0], plots_data[0], f"1 producer, 11 consumers{warm_up_tile}") - get_subplot(ax[0, 1], plots_data[1], f"4 producers, 8 consumers{warm_up_tile}") - get_subplot(ax[1, 0], plots_data[2], f"8 producers, 4 consumers{warm_up_tile}") - get_subplot(ax[1, 1], plots_data[3], f"11 producers, 1 consumer{warm_up_tile}") - - plt.savefig(output_file, transparent=True) - - -data = output_2_dict() -data_with_warm_up = [x for x in data if x["warm_up"]] -data_without_warm_up = [x for x in data if not x["warm_up"]] - -get_plot(data_with_warm_up, True, "warm-up.pdf") -get_plot(data_without_warm_up, False, "no-warm-up.pdf") diff --git a/test/csv/coarse-list.csv b/test/csv/coarse-list.csv new file mode 100644 index 0000000000000000000000000000000000000000..965d0e0a76771f3762d08c91701c0fde5ef30c70 --- /dev/null +++ b/test/csv/coarse-list.csv @@ -0,0 +1,6 @@ +6.071738696067809360e+04,2.786482165908699972e+04,1.282883444052318555e+04 +6.020610939458831126e+04,2.850682305270217330e+04,1.280920732683843380e+04 +5.949030146316117316e+04,2.870580205777705123e+04,1.201513009862789295e+04 +5.748590364054343081e+04,2.900892497573810761e+04,1.254255870887301171e+04 +5.979635585218259075e+04,1.257640717161504290e+04,2.751934518967092299e+04 +5.741106151107072219e+04,2.831198699533703621e+04,1.260607534415254850e+04 diff --git a/test/output-csv.py b/test/output-csv.py new file mode 100644 index 0000000000000000000000000000000000000000..5582e45bf4a19ba7d3a705a5c93594b4778726fb --- /dev/null +++ b/test/output-csv.py @@ -0,0 +1,45 @@ +import os +import sys +import numpy as np + +output_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "output") + + +def get_result_from_line(line): + return line.split(":")[1].strip() + + +def get_data_from_test(file): + with open(file, "r") as lines: + for line in lines: + if line.startswith("Initial list size"): + size = int(get_result_from_line(line)) + elif line.startswith("Number of threads"): + threads = int(get_result_from_line(line)) + elif line.startswith("Operations throughput per second"): + throughput = float(get_result_from_line(line)) + return size, threads, throughput + + +def get_size_index(size): + if size == 1000: + return 0 + elif size == 2000: + return 1 + elif size == 3000: + return 2 + return None + + +def output_2_array(): + data = [[], [], [], [], [], []] + for f in os.listdir(output_folder): + if not f.endswith(".txt"): + continue + size, threads, throughput = get_data_from_test(os.path.join(output_folder, f)) + data[int(threads / 2 - 1)].insert(get_size_index(size), throughput) + return data + + +data = output_2_array() +np.savetxt(sys.argv[1], np.asarray(data), delimiter=",") diff --git a/test/plot.py b/test/plot.py new file mode 100644 index 0000000000000000000000000000000000000000..2e111a61e54d6588756c62a6df6d7b9e0b5a4963 --- /dev/null +++ b/test/plot.py @@ -0,0 +1,19 @@ +import sys +import matplotlib +import matplotlib.pyplot as plt +import numpy as np + + +x = np.arange(2, 14.0, 2) +y = np.loadtxt(sys.argv[1], delimiter=",", dtype=float) + +fig, ax = plt.subplots(figsize=(12, 8)) +ax.plot(x, y, marker="X") +ax.legend(["1k", "2k", "3k"]) + +ax.set( + xlabel="Threads", ylabel="Throughput (operations/second)", title=sys.argv[2], +) +ax.grid() + +fig.savefig(f"{sys.argv[2].replace(' ', '')}.pdf") diff --git a/test/scripts/generate-plots.py b/test/scripts/generate-plots.py new file mode 100755 index 0000000000000000000000000000000000000000..134a8966c85e12964667c1baf1f4bacc3d1cf369 --- /dev/null +++ b/test/scripts/generate-plots.py @@ -0,0 +1,3 @@ +#!/bin/bash + +python plot.py csv/coarse-list.csv "Coarse List Throughput" \ No newline at end of file diff --git a/test/run-tests.sh b/test/scripts/run-tests.sh similarity index 71% rename from test/run-tests.sh rename to test/scripts/run-tests.sh index c2aa3b2595a43d2883fe6484812b6aea870a3814..42dc93c1709db88d9ece4f71d35e195510f2bfe7 100755 --- a/test/run-tests.sh +++ b/test/scripts/run-tests.sh @@ -6,8 +6,10 @@ ant cd - mkdir output -initial_sizes=(100000 200000 300000) -capacities=(300000 500000 1000000) +# initial_sizes=(100000 200000 300000) +# capacities=(300000 500000 1000000) +initial_sizes=(1000 2000 3000) +capacities=(3000 5000 10000) threads=(2 4 6 8 10 12) for ((i = 0; i < 3; i++)); do for t in "${threads[@]}"; do