-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmarks for printing and saving tables
- Loading branch information
1 parent
78940cf
commit f6587cc
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from Orange.data import ContinuousVariable | ||
from .base import Benchmark, benchmark | ||
|
||
|
||
class BenchContinuous(Benchmark): | ||
|
||
@benchmark() | ||
def bench_str_val_decimals(self): | ||
a = ContinuousVariable("a", 4) | ||
for _ in range(1000): | ||
a.str_val(1.23456) | ||
|
||
@benchmark() | ||
def bench_str_val_g(self): | ||
a = ContinuousVariable("a") | ||
for _ in range(1000): | ||
a.str_val(1.23456) |