forked from scandum/crumsort
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm also removing "re-enable optimizations for primitive types" from the todo list because based on the benchmarks I'm not sure it's worth the effort.
- Loading branch information
Showing
15 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from tqdm import tqdm | ||
import fileinput | ||
|
||
TEST_DISPLAY_NAMES = { | ||
'ascending order' : 'ascending', | ||
'descending order' : 'descending', | ||
'random int' : 'random', | ||
'random order' : 'random high bits', | ||
'random' : 'crumsort (C)', | ||
'quadsort' : 'quadsort (C)', | ||
'skasort' : 'ska_sort' | ||
} | ||
|
||
EXCLUDE_TESTS = [ 'random double', 'random long' ] | ||
|
||
ALGORITHM_DISPLAY_NAMES = { | ||
'sort' : 'std::sort', | ||
'stablesort' : 'std::stable_sort', | ||
'cxcrumsort' : 'crumsort (C++)', | ||
'cxquadsort' : 'quadsort (C++)', | ||
'crumsort' : 'crumsort (C)', | ||
'quadsort' : 'quadsort (C)', | ||
'skasort' : 'ska_sort' | ||
} | ||
|
||
EXCLUDE_ALGORITHMS = [ 'blitsort', 'fluxsort', 'gridsort' ] | ||
|
||
EXPECTED_X_VALUES = [ 10, 100, 1000, 10000, 100000 ] | ||
|
||
benchmark_results = {} | ||
|
||
for line in fileinput.input(): | ||
|
||
line = line.strip() | ||
|
||
if len(line) > 0 and line[0] == '|' and line[-1] == '|': # This line actually has a table row | ||
|
||
# Parse the table row | ||
cells = line.split('|')[1:-1] # Throw out empty first and last elements | ||
cells = [c.strip() for c in cells] | ||
if cells[0] == 'Name' or len(cells[0]) == 0 or cells[0][0] == '-': # Throw out header rows | ||
continue | ||
|
||
# Extract the benchmark results | ||
algorithm = cells[0] | ||
array_len = int(cells[1]) | ||
time = float(cells[4]) | ||
test_name = cells[-1] | ||
|
||
# Store results in the global result table | ||
benchmark_results.setdefault(test_name, {}) | ||
benchmark_results[test_name].setdefault(algorithm, {}) | ||
benchmark_results[test_name][algorithm][array_len] = time | ||
|
||
# Bar graphs | ||
for test in tqdm(benchmark_results): | ||
|
||
if test in EXCLUDE_TESTS: | ||
continue | ||
|
||
test_name = TEST_DISPLAY_NAMES.get(test, test) | ||
|
||
fig, ax = plt.subplots() | ||
|
||
labels = [] | ||
values = [] | ||
|
||
for algorithm in sorted(benchmark_results[test].keys()): | ||
|
||
if algorithm in EXCLUDE_ALGORITHMS: | ||
continue | ||
|
||
algorithm_name = ALGORITHM_DISPLAY_NAMES.get(algorithm, algorithm) | ||
|
||
labels.append(algorithm_name) | ||
values.append(benchmark_results[test][algorithm][10000]) | ||
|
||
y_pos = np.arange(len(labels)) | ||
plt.barh(y_pos, values, align='center') | ||
plt.yticks(y_pos, labels) | ||
plt.xlabel('run time (ms)') | ||
plt.title(test_name + ' (10,000 elements)') | ||
plt.tight_layout() | ||
|
||
fig.savefig(test_name + " 10000.png") | ||
plt.close() | ||
|
||
# Line/scaling graphs | ||
for test in tqdm(benchmark_results): | ||
|
||
if test in EXCLUDE_TESTS: | ||
continue | ||
|
||
test_name = TEST_DISPLAY_NAMES.get(test, test) | ||
|
||
fig, ax = plt.subplots() | ||
ax.set_xscale('log') | ||
ax.set_yscale('log') | ||
|
||
ax.set(xlabel='array length', ylabel='run time (ms)', title=test) | ||
|
||
for algorithm in sorted(benchmark_results[test].keys()): | ||
|
||
if algorithm in EXCLUDE_ALGORITHMS: | ||
continue | ||
|
||
algorithm_name = ALGORITHM_DISPLAY_NAMES.get(algorithm, algorithm) | ||
|
||
times = benchmark_results[test][algorithm] | ||
array_lens = [key for key in times] | ||
array_lens.sort() | ||
datapoints = [times[array_len] for array_len in array_lens] | ||
datapoints = np.array(datapoints) | ||
|
||
ax.plot(array_lens, datapoints, label=algorithm_name) | ||
|
||
ax.legend() | ||
fig.savefig(test_name + ".png") | ||
plt.close() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.