Skip to content

Commit

Permalink
added benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbahng committed Jan 4, 2025
1 parent da3ea9d commit df868b2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install "pybind11[global]"
pip install numpy
- name: Compile aten
shell: pwsh
Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions test/benchmarks.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit df868b2

Please sign in to comment.