basnijholt / pfapack

Efficient numerical computation of the Pfaffian for dense and banded skew-symmetric matrices
https://arxiv.org/abs/1102.3440
Other
15 stars 6 forks source link

benchmark C vs Python #1

Open basnijholt opened 4 years ago

basnijholt commented 4 years ago

Small test script:

import time

import numpy.matlib
import numpy as np
import matplotlib.pyplot as plt
from pfapack.ctypes import pfaffian as cpf
from pfapack import pfaffian as pf

%matplotlib inline

t_python = []
t_c = []
ns = np.geomspace(100, 10000, 30)
for i in ns:
    i = int(i)
    A = numpy.matlib.rand(i, i)
    A = A - A.T

    t = time.time()
    for _ in range(5):
        pfa1 = pf.pfaffian(A)
    t_python.append(time.time() - t)

    t = time.time()
    for _ in range(5):
        pfa1 = cpf(A)
    t_c.append(time.time() - t)

fig, ax = plt.subplots()
line, = ax.plot(ns, t_python, color='blue', lw=2, label="Python")
line, = ax.plot(ns, t_c, color='red', lw=2, label="Python")
ax.set_yscale('log')
plt.show()
basnijholt commented 4 years ago
>>> A = numpy.matlib.rand(1000, 1000)
>>> A = A - A.T
>>> %timeit pfa1 = pf.pfaffian(A)
>>> %timeit pfa1 = cpf(A)
1.54 s ± 158 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
69 ms ± 1.97 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)