News for hackers. Stuff that matters.
Re:Faster TypedArrays: Vector Addition in WebAssembly by brrrrrm on Sunday January 02, 2022 @01:08PM (#29771577)
I believe numpy is bounded by Python's interpreter (which runs at about ~1us per dispatch to C function from what I recall while working on PyTorch). The number you get is definitely what I'd expect.

If you use larger arrays (and use the "out" variant: `numpy.add(a, b, out=c)`), you might get similar total throughput at least.

  import numpy as np

  N = 1024 * 128
  A = np.random.randn(N)
  B = np.random.randn(N)
  C = np.random.randn(N)

  import time

  for _ in range(1000):
    np.add(A, B, out=C)

  iters = 1000
  t = time.time()
  for _ in range(iters):
    np.add(A, B, out=C)
  d = time.time() - t
  print(f"{iters * N * 3 * 4 / d / 1e9:.2f} GB/s")

There are no comments on this comment yet.