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

test: more DB/ORM/QB benchmarks #6

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
12 changes: 12 additions & 0 deletions caffeination/microbenchmarks/bench_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ def bench_get_value_simple():
status.append(frappe.db.get_value("Role", role, "disabled"))


def bench_get_value_with_dict_filters():
return frappe.db.get_value("Role", {"creation": (">", "2020-01-01 00:00:00")}, "disabled")


def bench_get_value_with_list_filters():
return frappe.db.get_value("Role", ["creation", ">", "2020-01-01 00:00:00"], "*")


def bench_get_cached_value_simple():
status = []
for _ in range(10):
Expand Down Expand Up @@ -37,6 +45,10 @@ def bench_select_star():
return results


def bench_sql_select_many_rows():
return frappe.db.sql("select * from `tabDocField` order by creation limit 1000")


@lru_cache
def get_all_roles():
return frappe.get_all("Role", order_by="creation asc", limit=10, pluck="name")
22 changes: 22 additions & 0 deletions caffeination/microbenchmarks/bench_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ def bench_get_local_cached_doc():
return docs


def bench_get_all():
return frappe.get_all("DocField", "*", limit=1, run=0)


def bench_get_list():
return frappe.get_list("Role", "*", limit=20, run=0)


def bench_get_all_with_filters():
return frappe.get_all("Role", {"creation": (">", "2020-01-01 00:00:00")}, "disabled", limit=10, run=0)


def bench_get_all_with_many_fields():
return frappe.get_all(
"Role",
{"creation": (">", "2020-01-01 00:00:00")},
["disabled", "name", "creation", "modified"],
limit=10,
run=0,
)


@lru_cache
def get_all_roles():
return frappe.get_all("Role", order_by="creation asc", limit=10, pluck="name")
41 changes: 41 additions & 0 deletions caffeination/microbenchmarks/bench_qb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import frappe


def bench_qb_select_star():
table = frappe.qb.DocType("Role")
return frappe.qb.from_(table).select("*").limit(20).run(run=0)


def bench_qb_select_star_multiple_fields():
table = frappe.qb.DocType("Role")
return frappe.qb.from_(table).select(table.name, table.creation, table.modified).limit(20).run(run=0)


def bench_qb_get_query():
return frappe.qb.get_query(
"Role",
filters={"creation": (">", "2020-01-01 00:00:00")},
fields="disabled",
limit=10,
order_by="creation asc",
).run(run=0)


def bench_qb_get_query_multiple_fields():
return frappe.qb.get_query(
"Role",
filters={"creation": (">", "2020-01-01 00:00:00")},
fields=["disabled", "name", "creation", "modified"],
limit=10,
order_by="creation asc",
).run(run=0)


def bench_qb_simple_get_query():
return frappe.qb.get_query(
"Role",
filters={"name": "Guest"},
fields="*",
limit=1,
order_by="creation asc",
).run(run=0)
10 changes: 9 additions & 1 deletion caffeination/microbenchmarks/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
bench_background_jobs,
bench_database,
bench_orm,
bench_qb,
bench_redis,
bench_web_requests,
)
Expand Down Expand Up @@ -54,7 +55,14 @@ def teardown(site):


def discover_benchmarks(benchmark_filter):
benchmark_modules = [bench_orm, bench_database, bench_redis, bench_background_jobs, bench_web_requests]
benchmark_modules = [
bench_orm,
bench_database,
bench_redis,
bench_background_jobs,
bench_web_requests,
bench_qb,
]

benchmarks = []
for module in benchmark_modules:
Expand Down
Loading