File: bench_basic.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (76 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from Orange.data import Table
from Orange.preprocess import Discretize
from Orange.preprocess.discretize import EqualFreq
from .base import Benchmark, benchmark, pandas_only, non_pandas_only

# noinspection PyBroadException
try:
    from Orange.data.filter import FilterContinuous, FilterDiscrete, Values
except:  # pylint: disable=bare-except
    # legacy only
    pass


# noinspection PyStatementEffect
class BenchBasic(Benchmark):
    def setUp(self):
        self.iris = Table('iris')
        self.adult = Table('adult')
        self.discretizer = Discretize(EqualFreq(n=3))

    @benchmark(number=100)
    def bench_iris_read(self):
        Table('iris')

    @benchmark(number=5, warmup=1)
    def bench_adult_read(self):
        Table('adult')

    @benchmark(number=100)
    def bench_iris_create_X(self):
        self.iris.X

    @benchmark(number=50)
    def bench_adult_create_X(self):
        self.adult.X

    @pandas_only
    @benchmark(number=20)
    def bench_adult_filter_pandas(self):
        self.adult[(self.adult.age > 30) & (self.adult.workclass == 'Private')]

    @non_pandas_only
    @benchmark(number=20)
    def bench_adult_filter_pre_pandas(self):
        age_filter = FilterContinuous(self.adult.domain["age"], FilterContinuous.Greater, 30)
        workclass_filter = FilterDiscrete(self.adult.domain["workclass"], [0])
        combined = Values([age_filter, workclass_filter])
        combined(self.adult)

    @benchmark(number=50)
    def bench_iris_basic_stats(self):
        self.iris._compute_basic_stats()

    @benchmark(number=20)
    def bench_iris_distributions(self):
        self.iris._compute_distributions()

    @benchmark()
    def bench_iris_contingency(self):
        self.iris._compute_contingency()

    @benchmark()
    def bench_iris_discretize(self):
        self.discretizer(self.iris)

    @pandas_only
    @benchmark()
    def bench_iris_iteration_pandas(self):
        for _, _ in self.iris.iterrows():
            pass

    @non_pandas_only
    @benchmark()
    def bench_iris_iteration_pre_pandas(self):
        for _ in self.iris:
            pass