Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fenilgmehta committed Aug 12, 2019
2 parents 45a0995 + 8b20424 commit 627729d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 33 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ Graph
Stats
----------------------------------
* Results for ```Array length = 781250```, ```Object size = 4 K bytes = vector<uint64_t>[512]```, ```Array size = 2.98 GB```:
- 6.32 times faster than C++ STL std::sort
- 5.55 times faster than std::stable_sort
- 3.80 times faster than pdqsort
- 3.15 times faster than spinsort
- 2.82 times faster than timsort
- 2.55 times faster than flat_stable_sort
- 2.22 times faster than spreadsort
- 1.53 times faster than skasort
- Heavy comparison: The comparison is the sum of all the numbers of the array
- Light comparison: The comparison is with the first element of the array, as a key

| Sorting technique | Heavy Comparison time | Light Comparison time |
|:--------------------:|:---------------------:|:---------------------:|
| fm_sort optimization | x | y |
| C++ STL std::sort | 6.32x | 2.98y |
| std::stable_sort | 5.54x | 15.03y |
| pdqsort | 3.80x | 1.99y |
| spinsort | 3.15x | 5.95y |
| timsort | 2.83x | 6.72y |
| flat_stable_sort | 2.55x | 5.03y |
| spreadsort | 2.23x | 1.73y |
| skasort | 1.53x | 2.77y |


* Test conditions:
1. Compiled using "g++ -std=c++17 -O2 -m64 -march=native" for testing
Expand Down
Binary file modified graphs_and_analysis/Graphs_v3/Figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 88 additions & 25 deletions graphs_and_analysis/Graphs_v3/graph_plotter_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,120 @@
import matplotlib.pyplot as plt
import seaborn as sns


def add_bar_size(ax):
for p in ax.patches:
ax.annotate(f"{p.get_height():.0f}", (p.get_x() * 1.005, p.get_height() * 1.005))


# INPUT
names = np.array(["std::sort", "pdqsort", "std::stable_sort", "spinsort", "flat_stable_sort", "spreadsort", "timsort", "skasort", "fm_sort\noptimization"])[::-1]
Averages = [174.19, 30.06, 104.68, 20.04, 152.71, 151.56, 86.94, 59.96, 70.32, 50.75, 61.38, 17.42, 77.88, 67.69, 42.41, 27.85, 27.55, 10.08][::-1]
comparison_type = ["Light comparison", "Heavy comparison"]
names_init = np.array(["std::sort", "pdqsort", "std::stable_sort", "spinsort", "flat_stable_sort", "spreadsort", "timsort", "skasort", "fm_sort\noptimization"])
names_rev = names_init[::-1]
averages_init = [174.19, 30.06, 104.68, 20.04, 152.71, 151.56, 86.94, 59.96, 70.32, 50.75, 61.38, 17.42, 77.88, 67.69, 42.41,
27.85, 27.55, 10.08]
averages_rev = averages_init[::-1]
range_limit = 1000
graph_title = 'Array size = 2.98 GB\nArray length = 781250\nObject size = 4 K bytes = vector<uint64_t>[512]'
y_label_name = f'Running time - normalized to range[0, {range_limit}]'

names2 = []
for i in names:
for i in names_rev:
names2.append(i)
names2.append(i)

v1 = np.array(Averages[::2])
v2 = np.array(Averages[1::2])
v1 = v1 * range_limit / v1.max()
v2 = v2 * range_limit / v2.max()
v1_light_init = np.array(averages_rev[::2])
v2_heavy_init = np.array(averages_rev[1::2])
v1_light_norm = v1_light_init * range_limit / v1_light_init.max()
v2_heavy_norm = v2_heavy_init * range_limit / v2_heavy_init.max()

p1 = pd.DataFrame([names, v1]).T
p2 = pd.DataFrame([names, v2]).T
p3 = pd.DataFrame([names2, Averages, len(names)*["Light comparison","Heavy comparison"]], index=["Sorting technique", "Average execution time" ,"Data comparision type"]).T
p1 = pd.DataFrame([names_rev, v1_light_norm]).T
p2 = pd.DataFrame([names_rev, v2_heavy_norm]).T
p3 = pd.DataFrame([names2, averages_rev, len(names_rev) * ["Light comparison", "Heavy comparison"]],
index=["Sorting technique", "Average execution time", "Data comparison type"]).T
p3["Average execution time"] = p3["Average execution time"] * range_limit / p3["Average execution time"].max()

##########################################################################
# GRAPH type 1
x_pos = range(len(names))
plt.bar(x_pos, v1)
plt.xticks(x_pos, names)
plt.yticks(range(0, range_limit+1, range_limit//10), [str(i) for i in range(0, range_limit+1, range_limit//10)])
x_pos = range(len(names_rev))
plt.bar(x_pos, v1_light_norm)
plt.xticks(x_pos, names_rev)
plt.yticks(range(0, range_limit + 1, range_limit // 10), [str(i) for i in range(0, range_limit + 1, range_limit // 10)])
plt.ylabel(y_label_name)
plt.title(graph_title)
plt.show()


##########################################################################
# GRAPH type 2
def change_width(ax, new_value):
for patch in ax.patches:
current_width = patch.get_width()
diff = current_width - new_value

# we change the bar width
patch.set_width(new_value)

# we recenter the bar
patch.set_x(patch.get_x() + diff * .5)


# https://seaborn.pydata.org/generated/seaborn.barplot.html
sns.set(style="whitegrid")
ax = sns.barplot(x="Sorting technique", y="Average execution time", hue="Data comparision type", data=p3, palette=sns.color_palette("coolwarm", 17)[0::16] )
ax = sns.barplot(x="Data comparison type", y="Average execution time", hue="Sorting technique", data=p3,
palette=sns.color_palette())
# ax.axhline(0, color="k", clip_on=False)

for p in ax.patches:
ax.annotate(f"{p.get_height():.0f}", (p.get_x() * 1.005, p.get_height() * 1.005))

# for ticks in ax.xaxis.get_major_ticks():
# if ticks.label1.get_text() == names[-1]:
# # ticks.label1.set_facecolor("red")
# # ax.patches[p3.index.get_indexer([ticks.label1.get_text()])[0]].set_facecolor('red')
# ax.patches[p3.index.get_indexer([ticks.label1.get_text()])[0]].set_facecolor('red')
add_bar_size(ax)
change_width(ax, 0.15)

plt.yticks(range(0, range_limit+1, range_limit//10), [str(i) for i in range(0, range_limit + 1, range_limit//10)])
plt.yticks(range(0, range_limit + 1, range_limit // 10), [str(i) for i in range(0, range_limit + 1, range_limit // 10)])
plt.ylabel(y_label_name)
plt.xlabel("")
plt.title(graph_title)
plt.tight_layout(h_pad=2)
# plt.tight_layout(h_pad=2)
plt.show()
# plt.savefig("Figure_1.png", bbox_inches='tight', dpi=600)

##########################################################################
# GRAPH type 3 - BEST
# import matplotlib.pyplot as plt
# import matplotlib.cm as mplcm
# import matplotlib.colors as colors
# NUM_COLORS = len(names_rev)
# cm = plt.get_cmap('gist_rainbow')
# cNorm = colors.Normalize(vmin=0, vmax=NUM_COLORS-1)
# scalarMap = mplcm.ScalarMappable(norm=cNorm, cmap=cm)
# # ax.set_color_cycle([scalarMap.to_rgba(i) for i in range(NUM_COLORS)])
# plt.colorbar(scalarMap)

df3 = pd.DataFrame([v1_light_norm, v2_heavy_norm], index=comparison_type, columns=names_rev)
index = np.arange(len(df3))
bar_width = 0.095
opacity = 1.0

fig, ax = plt.subplots()

for i in range(len(df3.columns)):
ax.bar(index + i * bar_width, df3.values[:, i], bar_width, alpha=opacity, label=df3.columns[i])

add_bar_size(ax)

ax.set_xticks(index + len(df3.columns)*bar_width/2 - bar_width/2)
ax.set_xticklabels(comparison_type)
ax.set_xlabel("")
ax.set_ylabel(y_label_name)
ax.set_title(graph_title)
ax.legend()

current_palette = sns.color_palette()
# sns.palplot(current_palette)
plt.legend(current_palette)

fig.tight_layout()
plt.show()

##########################################################################

# REFER: https://seaborn.pydata.org/tutorial/color_palettes.html
# REFER: https://seaborn.pydata.org/examples/color_palettes.html
Expand Down

0 comments on commit 627729d

Please sign in to comment.