Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get asv benchmark suite running again. #641

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
43 changes: 15 additions & 28 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
# Write the benchmarking functions here.
# See "Writing benchmarks" in the asv docs for more information.
import subprocess
import time

from tiled.client import from_uri
import numpy

HOST = "0.0.0.0"
PORT = 9040
from tiled.adapters.array import ArrayAdapter
from tiled.adapters.mapping import MapAdapter
from tiled.client import Context, from_context
from tiled.server.app import build_app


class TimeSuite:
"""
An example benchmark that times the performance of various kinds
of iterating over dictionaries in Python.
"""

def setup(self):
self.server_process = subprocess.Popen(
Copy link
Member Author

@danielballan danielballan Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that instead of starting a server in a subprocess, this PR runs the server and client in the same process. Messages are passed directly via Python function calls, the same as it works in unit tests. This takes networking out of the equation and will give more stable results, focused on actual Tiled performance.

(f"uvicorn tiled.server.app:app --host {HOST} --port {PORT}").split()
)
time.sleep(5)
self.tree = from_uri(f"http://{HOST}:{PORT}", token="secret")
tree = MapAdapter({"x": ArrayAdapter.from_array(numpy.ones((100, 100)))})
app = build_app(tree)
self.context = Context.from_app(app)
self.client = from_context(self.context)

def teardown(self):
self.server_process.terminate()
self.server_process.wait()
self.context.close()

def time_list_tree(self):
list(self.tree)

def time_metadata(self):
self.tree["medium"]["ones"].metadata

def time_structure(self):
self.tree["medium"]["ones"].structure()
list(self.client)

def time_read(self):
self.tree["medium"]["ones"].read()
def time_lookup(self):
self.client["x"]

def time_compute(self):
self.tree["medium"]["ones"].read().compute()
def time_lookup_and_read(self):
self.client["x"].read()
Loading