Skip to content

Instantly share code, notes, and snippets.

@colesbury
Created February 2, 2026 19:30
Show Gist options
  • Select an option

  • Save colesbury/7c0259e0779aff2cc563c7db298edf42 to your computer and use it in GitHub Desktop.

Select an option

Save colesbury/7c0259e0779aff2cc563c7db298edf42 to your computer and use it in GitHub Desktop.
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