Skip to content

Commit c8b7067

Browse files
committed
matmul: add plot
1 parent aec1785 commit c8b7067

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Matmul.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main():
3232
ax = fg.gca()
3333
ax.scatter(times.keys(), times.values())
3434

35-
ax.set_title(f"Matmul, N={p.N} {platform.system()}")
35+
ax.set_title(f"Matmul, N={p.N} {platform.system()} {platform.machine()}")
3636
ax.set_ylabel("run time [sec.]")
3737
# ax.set_yscale('log')
3838
ax.grid(True)
@@ -52,25 +52,25 @@ def benchmark_matmul(N: int, Nrun: int) -> T.Dict[str, float]:
5252
t = pb.run([matmul_exe, str(N), str(Nrun)], cdir, "fortran")
5353
times["Fortran\n" + compinf["fc"] + "\n" + compinf["fcvers"]] = t[0]
5454
except EnvironmentError:
55-
pass
55+
logging.error("Fortran compiler not found")
5656

5757
try:
5858
t = pb.run(["julia", "matmul.jl", str(N)], bdir)
5959
times["julia \n" + t[1]] = t[0]
6060
except EnvironmentError:
61-
pass
61+
logging.error("Julia not found")
6262

6363
try:
6464
t = pb.run(["gdl", "-q", "-e", "matmul", "-arg", str(N)], bdir)
6565
times["gdl \n" + t[1]] = t[0]
6666
except EnvironmentError:
67-
pass
67+
logging.error("GDL not found")
6868

6969
try:
7070
t = pb.run(["idl", "-quiet", "-e", "matmul", "-arg", str(N)], bdir)
7171
times["idl \n" + t[1]] = t[0]
7272
except EnvironmentError:
73-
pass
73+
logging.error("IDL not found")
7474

7575
# octave-cli, not octave in general
7676
try:
@@ -85,11 +85,8 @@ def benchmark_matmul(N: int, Nrun: int) -> T.Dict[str, float]:
8585
except EnvironmentError:
8686
logging.error("Matlab not found")
8787

88-
try:
89-
t = pb.run(["python", "matmul.py", str(N), str(Nrun)], bdir)
90-
times["python \n" + t[1]] = t[0]
91-
except EnvironmentError:
92-
pass
88+
t = pb.run(["python", "matmul.py", str(N), str(Nrun)], bdir)
89+
times["python \n" + t[1]] = t[0]
9390

9491
return times
9592

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Matrix Multiplication benchmarks:
4141
python Matmul.py
4242
```
4343

44+
![Matrix Multiplication benchmark](./gfx/matmul.png)
45+
4446
### Hypotenuse
4547

4648
Observe that `hypot()` is faster from 1 to a few hundred elements, then

RunHypot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import timeit
1111
import sys
1212
import shutil
13+
import platform
1314

1415
import numpy as np
1516

@@ -76,7 +77,9 @@ def plotspeed(N, pyrat, fortrat):
7677
ax.plot(N, fortrat, label="Fortran")
7778

7879
ax.set_title(
79-
f"timeit(sqrt(a**2+b**2)) / timeit(hypot(a,b)) \n Numpy {np.__version__} Python {pyver} Gfortran {fortver}"
80+
"timeit(sqrt(a**2+b**2)) / timeit(hypot(a,b))\n"
81+
f"Numpy {np.__version__} Python {pyver} Gfortran {fortver}\n"
82+
f"{platform.system()} {platform.machine()}"
8083
)
8184
ax.set_xscale("log")
8285
ax.legend(loc="best")

gfx/matmul.png

24 KB
Loading

0 commit comments

Comments
 (0)