File: issue-36.py

package info (click to toggle)
numexpr 2.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 784 kB
  • sloc: cpp: 4,250; python: 3,985; ansic: 369; makefile: 203
file content (37 lines) | stat: -rw-r--r-- 898 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
# Small benchmark to get the even point where the threading code
# performs better than the serial code.  See issue #36 for details.

from __future__ import print_function

from time import time

import numpy as np
from numpy.testing import assert_array_equal

import numexpr as ne


def bench(N):
    print("*** array length:", N)
    a = np.arange(N)
    t0 = time()
    ntimes = (1000*2**15) // N
    for i in range(ntimes):
        ne.evaluate('a>1000')
    print("numexpr--> %.3g" % ((time()-t0)/ntimes,))

    t0 = time()
    for i in range(ntimes):
        eval('a>1000')
    print("numpy--> %.3g" % ((time()-t0)/ntimes,))

if __name__ == "__main__":
    print("****** Testing with 1 thread...")
    ne.set_num_threads(1)
    for N in range(10, 20):
        bench(2**N)

    print("****** Testing with 2 threads...")
    ne.set_num_threads(2)
    for N in range(10, 20):
        bench(2**N)