-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now saving the memory consumed in object's instance too
- Loading branch information
1 parent
0b7c3de
commit 116c042
Showing
3 changed files
with
13 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,3 @@ | ||
import time as t | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
class Benchmark: | ||
|
||
def __init__(self): | ||
self.time = [] | ||
self.memory = [] | ||
self.plot = None | ||
self.functionName = None | ||
|
||
def run(self, func, *argv): | ||
self.functionName = func.__name__ | ||
start = t.time() | ||
# print(var) | ||
func(argv) | ||
end = t.time() | ||
runtime = end - start | ||
print(f'The runtime for {func.__name__} took {runtime} seconds to complete') | ||
return runtime | ||
|
||
def add(self, index, time=None, memory=None): | ||
self.time.append([index, time]) | ||
self.memory.append([index, memory]) | ||
|
||
def plotGraph(self, xlabel="", ylabel="", title="", label="", show=True, plt=plt): | ||
time = np.array(self.time) | ||
plt.plot(time[:,0],time[:,1], label=label) | ||
plt.xlabel(xlabel) | ||
plt.ylabel(ylabel) | ||
plt.title(title) | ||
if show: | ||
plt.show() | ||
return plt | ||
|
||
def compare(self, xlabel="", ylabel="", title="", *argv): | ||
temp = self.plotGraph(xlabel=xlabel, ylabel=ylabel, title=title, label=self.functionName, show=False, plt=plt) | ||
for other in argv: | ||
# time2 = np.array(other.time, plt=temp) | ||
# plt.plot(time2[:,0],time2[:,1]) | ||
other.plotGraph(xlabel=xlabel, ylabel=ylabel, title=title, label=other.functionName, show=False, plt=temp) | ||
temp.legend(loc="upper right") | ||
temp.show() | ||
|
||
from .Benchmark import Benchmark as bm | ||
__all__ = ["Benchmark"] | ||
Benchmark = bm |
Binary file not shown.