Skip to content

Commit

Permalink
benchmarks for printing and saving tables
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Apr 2, 2020
1 parent 78940cf commit c36d9bf
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
61 changes: 61 additions & 0 deletions benchmark/bench_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from functools import partial
import os

import numpy as np
import scipy.sparse

from Orange.data import Table, ContinuousVariable, Domain
from .base import Benchmark, benchmark


def save(table, fn):
try:
table.save(fn)
finally:
os.remove(fn)


class BenchSave(Benchmark):

def setup_dense(self, rows, cols, varkwargs=None):
if varkwargs is None:
varkwargs = {}
self.table = Table.from_numpy( # pylint: disable=W0201
Domain([ContinuousVariable(str(i), **varkwargs) for i in range(cols)]),
np.random.RandomState(0).rand(rows, cols))

def setup_sparse(self, rows, cols, varkwargs=None):
if varkwargs is None:
varkwargs = {}
sparse = scipy.sparse.rand(rows, cols, density=0.01, format='csr', random_state=0)
self.table = Table.from_numpy( # pylint: disable=W0201
Domain([ContinuousVariable(str(i), sparse=True, **varkwargs) for i in range(cols)]),
sparse)

@benchmark(setup=partial(setup_dense, rows=100, cols=10))
def bench_print_dense(self):
str(self.table)

@benchmark(setup=partial(setup_dense, rows=100, cols=10,
varkwargs={"number_of_decimals": 2}))
def bench_print_dense_decimals(self):
str(self.table)

@benchmark(setup=partial(setup_sparse, rows=100, cols=10), number=5)
def bench_print_sparse(self):
str(self.table)

@benchmark(setup=partial(setup_sparse, rows=100, cols=10,
varkwargs={"number_of_decimals": 2}),
number=5)
def bench_print_sparse_decimals(self):
str(self.table)

@benchmark(setup=partial(setup_dense, rows=100, cols=100))
def bench_save_tab(self):
save(self.table, "temp_save.tab")

@benchmark(setup=partial(setup_dense, rows=100, cols=100,
varkwargs={"number_of_decimals": 2}))
def bench_save_tab_decimals(self):
save(self.table, "temp_save.tab")
19 changes: 19 additions & 0 deletions benchmark/bench_variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from Orange.data import ContinuousVariable
from .base import Benchmark, benchmark


class BenchContinuous(Benchmark):

# pylint: disable=no-self-use
@benchmark()
def bench_str_val_decimals(self):
a = ContinuousVariable("a", 4)
for _ in range(1000):
a.str_val(1.23456)

# pylint: disable=no-self-use
@benchmark()
def bench_str_val_g(self):
a = ContinuousVariable("a")
for _ in range(1000):
a.str_val(1.23456)

0 comments on commit c36d9bf

Please sign in to comment.