Skip to content

Commit

Permalink
improved benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 11, 2022
1 parent 76dfb96 commit fd9a0fa
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 43 deletions.
30 changes: 22 additions & 8 deletions benchmarks/benchmarks.py
Expand Up @@ -4,6 +4,7 @@
from rich.color import Color, ColorSystem
from rich.console import Console
from rich.pretty import Pretty
from rich.segment import Segment
from rich.style import Style
from rich.syntax import Syntax
from rich.table import Table
Expand All @@ -16,9 +17,10 @@ def setup(self):
file=StringIO(), color_system="truecolor", legacy_windows=False
)
self.len_lorem_ipsum = len(snippets.LOREM_IPSUM)
self.text = Text.from_markup(snippets.MARKUP)

def time_wrapping(self):
Text(snippets.LOREM_IPSUM).wrap(self.console, 12, overflow="fold")
self.text.wrap(self.console, 12, overflow="fold")

def time_indent_guides(self):
Text(snippets.PYTHON_SNIPPET).with_indent_guides()
Expand All @@ -27,7 +29,7 @@ def time_fit(self):
Text(snippets.LOREM_IPSUM).fit(12)

def time_split(self):
Text(snippets.LOREM_IPSUM).split()
self.text.split()

def time_divide(self):
Text(snippets.LOREM_IPSUM).divide(range(20, 100, 4))
Expand All @@ -36,7 +38,7 @@ def time_align_center(self):
Text(snippets.LOREM_IPSUM).align("center", width=self.len_lorem_ipsum * 3)

def time_render(self):
Text(snippets.LOREM_IPSUM).render(self.console)
list(self.text.render(self.console))

def time_wrapping_unicode_heavy(self):
Text(snippets.UNICODE_HEAVY_TEXT).wrap(self.console, 12, overflow="fold")
Expand All @@ -48,15 +50,15 @@ def time_split_unicode_heavy(self):
Text(snippets.UNICODE_HEAVY_TEXT).split()

def time_divide_unicode_heavy(self):
Text(snippets.UNICODE_HEAVY_TEXT).divide(range(20, 100, 4))
self.text.divide(range(20, 100, 4))

def time_align_center_unicode_heavy(self):
Text(snippets.UNICODE_HEAVY_TEXT).align(
"center", width=self.len_lorem_ipsum * 3
)

def time_render_unicode_heavy(self):
Text(snippets.UNICODE_HEAVY_TEXT).render(self.console)
list(Text(snippets.UNICODE_HEAVY_TEXT).render(self.console))


class TextHotCacheSuite:
Expand Down Expand Up @@ -148,6 +150,8 @@ def setup(self):
self.console = Console(
file=StringIO(), color_system="truecolor", legacy_windows=False, width=100
)
self.style1 = Style.parse("blue on red")
self.style2 = Style.parse("green italic bold")

def time_parse_ansi(self):
Style.parse("red on blue")
Expand All @@ -158,6 +162,9 @@ def time_parse_hex(self):
def time_parse_mixed_complex_style(self):
Style.parse("dim bold reverse #00ee00 on rgb(123,12,50)")

def time_style_add(self):
self.style1 + self.style2


class ColorSuite:
def setup(self):
Expand Down Expand Up @@ -199,6 +206,13 @@ def time_downgrade_to_windows(self):

class SegmentSuite:
def setup(self):
self.console = Console(
file=StringIO(), color_system="truecolor", legacy_windows=False, width=100
)
self.line = [
Segment("foo"),
Segment("bar"),
Segment("egg"),
Segment("Where there is a Will"),
Segment("There is a way"),
] * 2

def test_divide_complex(self):
list(Segment.divide(self.line, [5, 10, 20, 50, 108, 110, 118]))

0 comments on commit fd9a0fa

Please sign in to comment.