Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/benchmark_render_c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#from ydnatl import *
import timeit
from ydnatl.tags.html import *
from ydnatl.tags.layout import *
from ydnatl.tags.text import *
from ydnatl.core.element import *

# Dynamic content based on conditions


iterations = 1000

python_time = timeit.timeit(
stmt="""
from ydnatl.tags.html import HTML, Head, Body, Title
from ydnatl.tags.layout import Div
from ydnatl.tags.text import H1, Paragraph
from ydnatl.core.element import HTMLElement

day_of_week = "Monday"
html = HTML()
header = Head()
body = Body()

body.append(
Div(
H1("My Headline"),
Paragraph("Basic paragraph element"),
)
)

if day_of_week == "Monday":
header.append(Title("Unfortunately, it's Monday!"))
else:
header.append(Title("Great! It's no longer Monday!"))

html.append(header)
html.append(body)


html.render()"""
)

cython_time = timeit.timeit(
stmt="""
from ydnatl.tags.html import HTML, Head, Body, Title
from ydnatl.tags.layout import Div
from ydnatl.tags.text import H1, Paragraph
from ydnatl.core.element import HTMLElement

day_of_week = "Monday"

html = HTML()
header = Head()
body = Body()

body.append(
Div(
H1("My Headline"),
Paragraph("Basic paragraph element"),
)
)

if day_of_week == "Monday":
header.append(Title("Unfortunately, it's Monday!"))
else:
header.append(Title("Great! It's no longer Monday!"))

html.append(header)
html.append(body)


html.render_c()""",
number=iterations
)

print(f"Python method: {python_time:.6f} seconds")
print(f"Cython method: {cython_time:.6f} seconds")
print(f"Speedup: {python_time / cython_time:.2f}x")

#print(html.render())
#print(html.render_c())
3 changes: 2 additions & 1 deletion src/ydnatl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .core.element import HTMLElement
from .core.cycode.cython_render import render_c
from .tags.form import (
Textarea,
Select,
Expand Down Expand Up @@ -144,4 +145,4 @@
"Subscript",
"Time",
"Code",
]
]
Empty file.
Loading