From 80d82f85285363ec05872a8ccf64295b148432f5 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 19 Dec 2024 15:27:30 +0530 Subject: [PATCH] bench: doc.save, new_doc, doc.as_dict + misc Also ensure that setup is completed during tests (as few things change after setup) --- .github/workflows/ci.yml | 1 + caffeine/microbenchmarks/bench_orm.py | 13 +++++++++++++ caffeine/microbenchmarks/bench_utils.py | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bbff8c..59581ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,6 +101,7 @@ jobs: working-directory: /home/runner/frappe-bench/sites run: | bench --site test_site set-config allow_tests true + bench --site test_site execute frappe.utils.install.before_tests bench --site test_site run-microbenchmarks -l2 -p2 -w0 --quiet env: TYPE: server diff --git a/caffeine/microbenchmarks/bench_orm.py b/caffeine/microbenchmarks/bench_orm.py index 8731d3a..0d84ea0 100644 --- a/caffeine/microbenchmarks/bench_orm.py +++ b/caffeine/microbenchmarks/bench_orm.py @@ -16,6 +16,16 @@ def bench_get_user(): return guest, admin +def bench_save_doc(): + # Thid doctype is used because it has nothing, + # so we are essentially measuring typical "overheads" + # No controversiez plz. + frappe.get_doc("Gender", "Other").save() + + +bench_new_doc = NanoBenchmark('frappe.new_doc("Role")') + + def bench_get_cached_doc(): docs = [] for role in get_all_roles(): @@ -58,3 +68,6 @@ def bench_get_local_cached_doc(): @lru_cache def get_all_roles(): return frappe.get_all("Role", order_by="creation asc", limit=10, pluck="name") + + +bench_doc_to_dict = NanoBenchmark("doc.as_dict()", setup='doc=frappe.get_doc("User", "Guest")') diff --git a/caffeine/microbenchmarks/bench_utils.py b/caffeine/microbenchmarks/bench_utils.py index b07151f..4166838 100644 --- a/caffeine/microbenchmarks/bench_utils.py +++ b/caffeine/microbenchmarks/bench_utils.py @@ -4,7 +4,7 @@ import frappe from frappe.utils import flt from frappe.utils.caching import redis_cache, request_cache, site_cache -from frappe.utils.data import cint +from frappe.utils.data import cint, get_datetime from caffeine.microbenchmarks.utils import NanoBenchmark @@ -98,3 +98,7 @@ def cache_in_redis(num): bench_unknown_translations = NanoBenchmark("""frappe._("Unknown Strngi", lang="de")""") bench_no_translation_required = NanoBenchmark("""frappe._("Unknown Strngi", lang="en")""") bench_valid_translation = NanoBenchmark("""frappe._("User", lang="de")""") + +bench_parse_datetime = NanoBenchmark( + "get_datetime('2042-12-22 00:01:02.000042')", setup="", globals={"get_datetime": get_datetime} +)