File: speedtest.py

package info (click to toggle)
python-npx 0.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: python: 330; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 617 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import perfplot

import npx

rng = np.random.default_rng(0)

m = 100


def setup(n):
    idx = rng.randomint(0, m, n)
    b = rng.random(n)
    return idx, b


def np_add_at(data):
    a = np.zeros(m)
    idx, b = data
    np.add.at(a, idx, b)
    return a


def npx_add_at(data):
    a = np.zeros(m)
    idx, b = data
    npx.add_at(a, idx, b)
    return a


def npx_sum_at(data):
    idx, b = data
    return npx.sum_at(b, idx, minlength=m)


b = perfplot.bench(
    setup=setup,
    kernels=[np_add_at, npx_add_at, npx_sum_at],
    n_range=[2**k for k in range(23)],
)
b.save("perf-add-at.svg")