Skip to content

Instantly share code, notes, and snippets.

@Jordan-Cottle
Last active April 15, 2021 19:29
Show Gist options
  • Save Jordan-Cottle/1632bc52e77c4524abb6839e3774ca63 to your computer and use it in GitHub Desktop.
Save Jordan-Cottle/1632bc52e77c4524abb6839e3774ca63 to your computer and use it in GitHub Desktop.
Markdown table generated with test data
Threads omp parallel + critical time omp parallel + critical speedup omp parallel for + dynamic schedule + critical time omp parallel for + dynamic schedule + critical speedup omp parallel for reduction + dynamic schedule time omp parallel for reduction + dynamic schedule speedup
1 0.8353 1.0 0.8803 1.0 0.8419 1.0
2 0.6286 1.328825962456252 0.6602 1.333383823083914 0.6454 1.3044623489308955
4 0.5071 1.6472096233484521 0.743 1.1847913862718709 0.7135 1.179957953749124
8 0.6104 1.3684469200524245 0.8871 0.9923345733288242 0.8807 0.955944135346883
16 0.916 0.9118995633187773 1.2146 0.7247653548493331 1.1635 0.7235926085088096
32 1.5991 0.5223563254330561 1.9379 0.4542546055007998 1.9206 0.43835259814641253
class Alignment(str, Enum):
LEFT = "<"
CENTER = "^"
RIGHT = ">"
NONE = ""
class Column:
def __init__(self, name, rows, align=Alignment.NONE):
self.name = name
self.rows = rows
self.align = align
self.width = max(len(self.name), *(len(str(row)) for row in self.rows))
if self.align == Alignment.CENTER:
sep = f":{'-' * (self.width-2)}:"
elif self.align == Alignment.LEFT:
sep = f":{'-' * (self.width-1)}"
elif self.align == Alignment.RIGHT:
sep = f"{'-' * (self.width-1)}:"
else: # align == Alignment.NONE:
sep = "-" * self.width
self.seperator = sep
def __iter__(self):
f_str = f"{{:{self.align}{self.width}}}"
rows = (
self.name,
self.seperator,
*self.rows,
)
return iter(f" {f_str.format(row)} " for row in rows)
class Table:
def __init__(self, headers, data, alignments=None):
self.headers = headers
self.data = data
if alignments is None:
alignments = {}
self.columns = [
Column(header, self.data[header], alignments.get(header, Alignment.CENTER))
for header in self.headers
]
def __str__(self):
return "\n".join(
[f"|{'|'.join(str(col) for col in row)}|" for row in zip(*self.columns)]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment