File: performance.py

package info (click to toggle)
lazyarray 0.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 228 kB
  • sloc: python: 1,251; makefile: 109
file content (53 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53


import numpy as np
from numpy.testing import assert_array_equal
from lazyarray import larray
from timeit import repeat


def test_function(i, j):
    return i * i + 2 * i * j + 3


def array_from_function_full(f, shape):
    return np.fromfunction(f, shape)


def larray_from_function_full(f, shape):
    return larray(f, shape).evaluate()


def array_from_function_slice(f, shape):
    return np.fromfunction(f, shape)[:, 0:-1:10]


def larray_from_function_slice(f, shape):
    return larray(f, shape)[:, 0:shape[1] - 1:10]


if __name__ == "__main__":
    assert_array_equal(array_from_function_full(test_function, (5000, 5000)),
                       larray_from_function_full(test_function, (5000, 5000)))

    print "Array from function: full array"
    print(repeat('array_from_function_full(test_function, (5000, 5000))',
                 setup='from __main__ import array_from_function_full, test_function',
                 number=1, repeat=5))

    print "Lazy array from function: full array"
    print(repeat('larray_from_function_full(test_function, (5000, 5000))',
                 setup='from __main__ import larray_from_function_full, test_function',
                 number=1, repeat=5))

    assert_array_equal(array_from_function_slice(test_function, (5000, 5000)),
                       larray_from_function_slice(test_function, (5000, 5000)))
    print "Array from function: slice"
    print(repeat('array_from_function_slice(test_function, (5000, 5000))',
                 setup='from __main__ import array_from_function_slice, test_function',
                 number=1, repeat=5))

    print "Lazy array from function: slice"
    print(repeat('larray_from_function_slice(test_function, (5000, 5000))',
                 setup='from __main__ import larray_from_function_slice, test_function',
                 number=1, repeat=5))