diff --git a/tests/test_app/components.py b/tests/test_app/components.py index 9500f01a..433bd9e4 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -1,6 +1,5 @@ import asyncio import inspect -from datetime import datetime from pathlib import Path from channels.db import database_sync_to_async @@ -25,23 +24,6 @@ from .types import TestObject -@component -def test_runner(): - start_time, _ = hooks.use_state(datetime.now()) - count, set_count = hooks.use_state(0) - seconds_elapsed = (datetime.now() - start_time).total_seconds() - - @hooks.use_effect - def run_tests(): - set_count(count + 1) - - return html.div( - {"id": "test-runner"}, - html.div(f"Total renders: {count}"), - html.div(f"Renders Per Second: {count / (seconds_elapsed or 0.01)}"), - ) - - @component def hello_world(): return html._(html.div({"id": "hello-world"}, "Hello World!")) diff --git a/tests/test_app/performance/__init__.py b/tests/test_app/performance/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_app/performance/components.py b/tests/test_app/performance/components.py new file mode 100644 index 00000000..9ee28afb --- /dev/null +++ b/tests/test_app/performance/components.py @@ -0,0 +1,23 @@ +from datetime import datetime + +from reactpy import component, hooks, html + + +@component +def renders_per_second(): + start_time, _ = hooks.use_state(datetime.now()) + count, set_count = hooks.use_state(0) + seconds_elapsed = (datetime.now() - start_time).total_seconds() + + @hooks.use_effect + def run_tests(): + set_count(count + 1) + + return html.div( + {"id": "test-runner"}, + html.div(f"Total renders: {count}"), + html.div( + {"class_name": "rps"}, + f"Renders Per Second: {count / (seconds_elapsed or 0.01)}", + ), + ) diff --git a/tests/test_app/performance/urls.py b/tests/test_app/performance/urls.py new file mode 100644 index 00000000..64ea8892 --- /dev/null +++ b/tests/test_app/performance/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from .views import renders_per_second + +urlpatterns = [ + path("rps/", renders_per_second), +] diff --git a/tests/test_app/performance/views.py b/tests/test_app/performance/views.py new file mode 100644 index 00000000..ff9ca6e5 --- /dev/null +++ b/tests/test_app/performance/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def renders_per_second(request): + return render(request, "renders_per_second.html", {}) diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index 4da6dd78..10eaac27 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -19,7 +19,76 @@