From 4162b2040bd20a4e95a570179e37fbf367023629 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Thu, 20 May 2021 11:10:55 +0200 Subject: [PATCH] Add function call benchmark This adds a benchmark that compares calling math.sin with doing the same using the PyObjC machinery. --- pyobjc-core/Tools/pyobjcbench.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pyobjc-core/Tools/pyobjcbench.py b/pyobjc-core/Tools/pyobjcbench.py index b07a16764a..b6fb85275e 100644 --- a/pyobjc-core/Tools/pyobjcbench.py +++ b/pyobjc-core/Tools/pyobjcbench.py @@ -72,3 +72,17 @@ def print_bench(title, time): stmt="m()", ), ) +print() +print_bench( + "python function call", + timeit.timeit(setup="import math; f=math.sin", stmt="f(5.0)"), +) +setup = """ +import objc +objc.loadBundleFunctions(None, globals(), [("sin", b"dd")]) +f = sin +""" +print_bench( + "objc function call", + timeit.timeit(setup=setup, stmt="f(5.0)"), +)