Benchmarks
Back to README | Reproduce:
examples/09_mean.py
This document contains the full performance benchmark comparing AsNumpy (NPU) against NumPy (CPU) on the mean() operation.
Test Environment
| Item | AsNumpy (NPU) | NumPy (CPU) |
|---|---|---|
| Processor | Ascend 910B NPU | Server CPU (AArch64) on the same machine |
| NPU Runtime | CANN 8.2.RC1.alpha003 | — |
| Python | Python 3.9+ | |
| Library version | AsNumpy 0.2.0 | NumPy 1.26+ |
| Data type | float32 | |
| Operation | mean() — arithmetic mean of all elements (axis=None) | |
| Timer | time.perf_counter() (high-resolution) | |
Controlled Variables
- Both sides use identical input data: arrays are generated by NumPy and transferred to NPU via
from_numpy()before timing starts. - Data transfer time is excluded: only the
mean()computation is timed. - Warmup: 40 warmup iterations are executed before timing to stabilize the NPU runtime.
- Test iterations: 400 iterations per shape.
- Statistical method: sort all measured times, exclude the slowest 10% (affected by system scheduling jitter), and take the minimum of the remaining data as the representative time (representing hardware peak performance).
Results
| Shape | Data Size | AsNumpy (ms) | NumPy (ms) | Speedup |
|---|---|---|---|---|
| (500, 500) | 250,000 | 0.1446 | 0.1429 | 0.99× |
| (1000, 1000) | 1,000,000 | 0.1510 | 0.4904 | 3.25× |
| (2000, 2000) | 4,000,000 | 0.1636 | 1.9372 | 11.84× |
| (3000, 3000) | 9,000,000 | 0.1857 | 6.6303 | 35.70× |
Key observation: For small tensors (500×500, 250K elements), NPU launch overhead is comparable to CPU compute time, making them nearly on par. As tensor size grows, NPU's massive parallelism takes over — achieving 35.70× speedup at 3000×3000 (9M elements). NPU execution time remains nearly constant across all tested shapes, demonstrating excellent scalability.
Reproducing the Results
Run the benchmark script from the project root:
python examples/09_mean.py
The script tests all four shapes with 40 warmup iterations and 400 test iterations each, applies a statistical trimming strategy (exclude slowest 10%, take minimum of remaining), and verifies numerical correctness against NumPy (relative diff < 1e-4).