Skip to content

Instantly share code, notes, and snippets.

@nrbnlulu
Created February 5, 2023 07:01
Show Gist options
  • Save nrbnlulu/7deeced080cd563c0749880f59e3ab1a to your computer and use it in GitHub Desktop.
Save nrbnlulu/7deeced080cd563c0749880f59e3ab1a to your computer and use it in GitHub Desktop.
from functools import partial
from timeit import timeit
from PySide6.QtCore import QCoreApplication, QObject, Slot
from qtgql import slot
def manual():
class ManualTyping(QObject):
@Slot(str, int, result="int")
def foo(self, a: str, b: int) -> int:
...
return ManualTyping
def auto():
class FromTypeHints(QObject):
@slot
def foo(self, a: str, b: int) -> int:
...
return FromTypeHints
if __name__ == "__main__":
app = QCoreApplication()
print(f"Manual - class creation time -> {timeit(manual, number=10000)}")
print(f"Auto - class creation time -> {timeit(auto, number=10000)}")
manual_typing = manual()
a = manual_typing()
part = partial(a.foo, "", 2)
print(f"call slot time for {manual_typing} -> {timeit(part, number=100000)}")
from_annotations = auto()
a = manual_typing()
part = partial(a.foo, "", 2)
print(f"call slot time for {from_annotations} -> {timeit(part, number=100000)}")
app.exec()
@nrbnlulu
Copy link
Author

nrbnlulu commented Feb 5, 2023

where qtgql is would be https://github.com/nrbnlulu/qtgql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment