Skip to content

Commit

Permalink
Add Test script and result for sort
Browse files Browse the repository at this point in the history
Ten separate command files are placed in `sort/` directory. The test can
be run in parallel using GNU parallel.
```
$ cat jobs.sh | parallel --group --bar -j8
```
The resulting stats and plot can be foundin `sort/stats` and
`sort/plots`.
  • Loading branch information
millaker committed Mar 17, 2024
1 parent 0702600 commit a956867
Show file tree
Hide file tree
Showing 66 changed files with 192,157 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
./qtest -f sort/sort1.cmd
./qtest -f sort/sort2.cmd
./qtest -f sort/sort3.cmd
./qtest -f sort/sort4.cmd
./qtest -f sort/sort5.cmd
./qtest -f sort/sort6.cmd
./qtest -f sort/sort7.cmd
./qtest -f sort/sort8.cmd
133 changes: 133 additions & 0 deletions process_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import sys
import os
from dataclasses import dataclass
import matplotlib.pyplot as plt
import numpy as np

@dataclass
class Stats:
name: str
pattern: int
size: list[int]
time: list[int]
cmps: list[int]

# Parse log file and return result lists for each type
# Returns a dictionary with type name as key and Stats
def process_file(file_name):
type = {}
try:
with open(file_name, "r") as file:
for line in file:
t, pattern, size, time, cmps = line.split()
if t not in type:
type[t] = Stats(t,pattern,[],[],[])
type[t].size.append(size)
type[t].time.append(time)
type[t].cmps.append(cmps)
except FileNotFoundError:
print(f"Error: File '{file_name}' not found.")
except Exception as e:
print(f"An error occurred while processing '{file_name}': {e}")
return type
pattern_dict = {1 : 'All random',
2 : 'Descending',
3 : 'Ascending',
4 : 'Ascend_3rand',
5 : 'Ascend_10_rand',
6 : 'Ascend_rand1%',
7 : 'Duplicates',
8 : 'All_Equal'}

def __plot(x, y, x_name, y_name, label, plot_name, file_name):
plt.figure(figsize=(10,6))
xticks = np.arange(0, 12000, 1000)
y_max = np.max(y)
step_size = 100
while y_max / step_size > 10:
step_size *= 10
yticks = np.arange(0, y_max + step_size, step_size)
plt.scatter(x, y, label=label, marker='+', s=15, alpha=0.8)
plt.xlabel(x_name)
plt.ylabel(y_name)
ax = plt.gca()
ax.set_xticks(xticks)
ax.set_yticks(yticks)
plt.xticks(rotation=30)
plt.title(plot_name)
plt.legend()
plt.savefig(file_name)
plt.close()

def __plot_mixed(x, data, y_name, data_name, plot_name, file_name):
# Draw mixed figure
plt.figure(figsize=(10,6))
max = -1
for d,n in zip(data,data_name):
plt.scatter(x, d, label=n, marker='+', s=15, alpha=0.8)
if np.max(d) > max:
max = np.max(d)
xticks = np.arange(0, 12000, 1000)
y_max = max
step_size = 100
while y_max / step_size > 10:
step_size *= 10
yticks = np.arange(0, y_max + step_size, step_size)
# Set labels and title
plt.xlabel('Size')
plt.ylabel(y_name)
ax = plt.gca()
ax.set_xticks(xticks)
ax.set_yticks(yticks)
plt.xticks(rotation=30)
plt.title(plot_name)
plt.legend()
plt.savefig(file_name)
plt.close()

def plot(result):
# Iterate through all sorting
size = 0
nameL = []
timeL = []
cmpsL = []
for d in result:
data=result[d]
plt.figure()
data = result[d]
pattern = data.pattern
# Convert to numpy array
size = np.array(data.size).astype(int)
time = np.array(data.time).astype(int)
cmps = np.array(data.cmps).astype(int)
timeL.append(time)
cmpsL.append(cmps)
nameL.append(data.name)

__plot(size, time, "Size", "Time", d, \
f'{data.name}sort {pattern_dict[int(pattern)]} -- Time', \
prefix + '/../plots/' + f'{data.name}_{pattern}_time.png')
__plot(size, cmps, "Size", "Comparisons", d, \
f'{data.name}sort {pattern_dict[int(pattern)]} -- Comparisons', \
prefix + '/../plots/' + f'{data.name}_{pattern}_cmps.png')
__plot_mixed(size, timeL, 'Size', nameL, \
f'Mixed {pattern_dict[int(pattern)]} -- Time', \
prefix + '/../plots/' + f'Mixed_{pattern}_time.png')
__plot_mixed(size, cmpsL, 'Size', nameL, \
f'Mixed {pattern_dict[int(pattern)]} -- Comparisons', \
prefix + '/../plots/' + f'Mixed_{pattern}_cmps.png')

if __name__ == "__main__":
if(len(sys.argv) < 2):
print(f"Usage: python {sys.argv[0]} input_file1 input_file2 ...")
sys.exit()
input_files = sys.argv[1:]
for i in input_files:
prefix = os.path.dirname(i)
result = process_file(i)
print(f'Plotting {i}...')
plot(result)




Binary file added sort/plots/Merge_1_cmps.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 sort/plots/Merge_1_time.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 sort/plots/Merge_2_cmps.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 sort/plots/Merge_2_time.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 sort/plots/Merge_3_cmps.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 sort/plots/Merge_3_time.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 sort/plots/Merge_4_cmps.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 sort/plots/Merge_4_time.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 sort/plots/Merge_5_cmps.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 sort/plots/Merge_5_time.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 sort/plots/Merge_6_cmps.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 sort/plots/Merge_6_time.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 sort/plots/Merge_7_cmps.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 sort/plots/Merge_7_time.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 sort/plots/Merge_8_cmps.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 sort/plots/Merge_8_time.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 sort/plots/Mixed_1_cmps.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 sort/plots/Mixed_1_time.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 sort/plots/Mixed_2_cmps.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 sort/plots/Mixed_2_time.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 sort/plots/Mixed_3_cmps.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 sort/plots/Mixed_3_time.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 sort/plots/Mixed_4_cmps.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 sort/plots/Mixed_4_time.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 sort/plots/Mixed_5_cmps.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 sort/plots/Mixed_5_time.png
Binary file added sort/plots/Mixed_6_cmps.png
Binary file added sort/plots/Mixed_6_time.png
Binary file added sort/plots/Mixed_7_cmps.png
Binary file added sort/plots/Mixed_7_time.png
Binary file added sort/plots/Mixed_8_cmps.png
Binary file added sort/plots/Mixed_8_time.png
Binary file added sort/plots/Tim_1_cmps.png
Binary file added sort/plots/Tim_1_time.png
Binary file added sort/plots/Tim_2_cmps.png
Binary file added sort/plots/Tim_2_time.png
Binary file added sort/plots/Tim_3_cmps.png
Binary file added sort/plots/Tim_3_time.png
Binary file added sort/plots/Tim_4_cmps.png
Binary file added sort/plots/Tim_4_time.png
Binary file added sort/plots/Tim_5_cmps.png
Binary file added sort/plots/Tim_5_time.png
Binary file added sort/plots/Tim_6_cmps.png
Binary file added sort/plots/Tim_6_time.png
Binary file added sort/plots/Tim_7_cmps.png
Binary file added sort/plots/Tim_7_time.png
Binary file added sort/plots/Tim_8_cmps.png
Binary file added sort/plots/Tim_8_time.png
2 changes: 2 additions & 0 deletions sort/sort1.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 1 100 12000 100 sort/stats/sort1.log
2 changes: 2 additions & 0 deletions sort/sort2.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 2 100 12000 100 sort/stats/sort2.log
2 changes: 2 additions & 0 deletions sort/sort3.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 3 100 12000 100 sort/stats/sort3.log
2 changes: 2 additions & 0 deletions sort/sort4.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 4 100 12000 100 sort/stats/sort4.log
2 changes: 2 additions & 0 deletions sort/sort5.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 5 100 12000 100 sort/stats/sort5.log
2 changes: 2 additions & 0 deletions sort/sort6.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 6 100 12000 100 sort/stats/sort6.log
2 changes: 2 additions & 0 deletions sort/sort7.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 7 100 12000 100 sort/stats/sort7.log
2 changes: 2 additions & 0 deletions sort/sort8.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do sort test
sorttestL 8 100 12000 100 sort/stats/sort8.log
Loading

0 comments on commit a956867

Please sign in to comment.