Skip to content

Commit

Permalink
bench: doc.save, new_doc, doc.as_dict + misc
Browse files Browse the repository at this point in the history
Also ensure that setup is completed during tests
(as few things change after setup)
  • Loading branch information
ankush committed Dec 19, 2024
1 parent 84986a8 commit 80d82f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions caffeine/microbenchmarks/bench_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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")')
6 changes: 5 additions & 1 deletion caffeine/microbenchmarks/bench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
)

0 comments on commit 80d82f8

Please sign in to comment.