-
-
Save colesbury/7c0259e0779aff2cc563c7db298edf42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| class MyClass: | |
| def __new__(cls, x, y=None): | |
| return super().__new__(cls) | |
| ITERATIONS = 1_000_000 | |
| # Warmup | |
| for _ in range(10_000): | |
| MyClass(1, 2) | |
| # Benchmark | |
| start = time.perf_counter_ns() | |
| for _ in range(ITERATIONS): | |
| MyClass(1, 2) | |
| end = time.perf_counter_ns() | |
| elapsed_ns = end - start | |
| per_call_ns = elapsed_ns / ITERATIONS | |
| print(f"{per_call_ns:.1f} ns/call") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment