From df868b27e0294ae27c90e7f32956eb9fa0348700 Mon Sep 17 00:00:00 2001 From: Muchang Bahng Date: Sat, 4 Jan 2025 15:09:13 -0500 Subject: [PATCH] added benchmark tests --- .github/workflows/run-tests.yml | 3 ++ test/benchmarks.py | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/benchmarks.py diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a2de2a3..55b9a1b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,6 +20,7 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip + pip install numpy - name: Compile aten run: | CMAKE_DEV=1 pip install . -vvv @@ -57,6 +58,7 @@ jobs: run: | python -m pip install --upgrade pip pip install "pybind11[global]" + pip install numpy - name: Compile aten shell: pwsh @@ -153,6 +155,7 @@ jobs: export Python_ROOT_DIR="${PYROOT}" ${PYROOT}/bin/pip install "pybind11[global]" + ${PYROOT}/bin/pip install numpy cd /pyember CMAKE_DEV=1 ${PYROOT}/bin/pip install -e . -vv diff --git a/test/benchmarks.py b/test/benchmarks.py new file mode 100644 index 0000000..410b757 --- /dev/null +++ b/test/benchmarks.py @@ -0,0 +1,51 @@ +import numpy as np +import ember +import time + +N = 100 + +def profile(f): + def wrapper(*args, **kwargs): + start = time.process_time() + _ = f(*args, **kwargs) + end = time.process_time() + return end - start + return wrapper + +x = np.random.randn(N, N) +y = np.random.randn(N, N) + +a = ember.Tensor.gaussian([N, N]) +b = ember.Tensor.gaussian([N, N]) + +@profile +def np_constructor(): return np.random.randn(N, N) +@profile +def em_constructor(): return ember.Tensor.gaussian([N, N]) + +@profile +def np_add(): return x + y +@profile +def em_add(): return a + b + +@profile +def np_diff(): return x - y +@profile +def em_diff(): return a - b + +@profile +def np_mul(): return x * y +@profile +def em_mul(): return a * b + +@profile +def np_matmul(): return x @ y +@profile +def em_matmul(): return a @ b + +print(f"Constructor Runtime Multiplier : {em_constructor() / np_constructor()}") # type: ignore +print(f"Addition Runtime Multiplier : {em_add() / np_add()}") # type: ignore +print(f"Subtraction Runtime Multiplier : {em_diff() / np_diff()}") # type: ignore +print(f"Multiplication Runtime Multiplier : {em_mul() / np_mul()}") # type: ignore +print(f"Mat Multiply Runtime Multiplier : {em_matmul() / np_matmul()}") # type: ignore +