Skip to content

Commit

Permalink
Add benchmark results
Browse files Browse the repository at this point in the history
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
psadda committed Sep 26, 2024
1 parent 530ccaa commit 781e5f9
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ Progress
- [x] Support types that do not a have a trivial default constructor
- [x] Support types that do not have *any* default constructor
- [x] Support move only types
- [ ] Re-enable optimizations for primitive types
- [ ] Update benchmarks
- [x] Update benchmarks
License
-------
Expand Down
121 changes: 121 additions & 0 deletions bench/plot.py
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()
Binary file added bench/results/ascending 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/ascending saw 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/ascending tiles 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/bit reversal 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/descending 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/descending saw 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/pipe organ 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random % 100 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random half 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random high bits 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random string 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bench/results/random tail 10000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 781e5f9

Please sign in to comment.