Skip to content

Commit

Permalink
Revert removal of Benchmark class
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Sep 24, 2018
1 parent 692d2b4 commit c0cf617
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 67 deletions.
6 changes: 4 additions & 2 deletions benchmarks/benchmarks/bench_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import absolute_import, division, print_function

from .common import Benchmark

import numpy as np

from six.moves import xrange


class LaplaceInplace(object):
class LaplaceInplace(Benchmark):
params = ['inplace', 'normal']
param_names = ['update']

Expand Down Expand Up @@ -51,7 +53,7 @@ def time_it(self, update):
self.run()


class MaxesOfDots(object):
class MaxesOfDots(Benchmark):
def setup(self):
np.random.seed(1)
nsubj = 5
Expand Down
16 changes: 9 additions & 7 deletions benchmarks/benchmarks/bench_core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import, division, print_function

from .common import Benchmark

import numpy as np


class Core(object):
class Core(Benchmark):
def setup(self):
self.l100 = range(100)
self.l50 = range(50)
Expand Down Expand Up @@ -74,7 +76,7 @@ def time_tril_l10x10(self):
np.tril(self.l10x10)


class Temporaries(object):
class Temporaries(Benchmark):
def setup(self):
self.amid = np.ones(50000)
self.bmid = np.ones(50000)
Expand All @@ -94,7 +96,7 @@ def time_large2(self):
(self.alarge + self.blarge) - 2


class CorrConv(object):
class CorrConv(Benchmark):
params = [[50, 1000, 1e5],
[10, 100, 1000, 1e4],
['valid', 'same', 'full']]
Expand All @@ -111,7 +113,7 @@ def time_convolve(self, size1, size2, mode):
np.convolve(self.x1, self.x2, mode=mode)


class CountNonzero(object):
class CountNonzero(Benchmark):
param_names = ['numaxes', 'size', 'dtype']
params = [
[1, 2, 3],
Expand All @@ -135,7 +137,7 @@ def time_count_nonzero_multi_axis(self, numaxes, size, dtype):
self.x.ndim - 1, self.x.ndim - 2))


class PackBits(object):
class PackBits(Benchmark):
param_names = ['dtype']
params = [[bool, np.uintp]]
def setup(self, dtype):
Expand All @@ -152,7 +154,7 @@ def time_packbits_axis1(self, dtype):
np.packbits(self.d2, axis=1)


class UnpackBits(object):
class UnpackBits(Benchmark):
def setup(self):
self.d = np.ones(10000, dtype=np.uint8)
self.d2 = np.ones((200, 1000), dtype=np.uint8)
Expand All @@ -167,6 +169,6 @@ def time_unpackbits_axis1(self):
np.unpackbits(self.d2, axis=1)


class Indices(object):
class Indices(Benchmark):
def time_indices(self):
np.indices((1000, 500))
20 changes: 11 additions & 9 deletions benchmarks/benchmarks/bench_function_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import, division, print_function

from .common import Benchmark

import numpy as np


class Histogram1D(object):
class Histogram1D(Benchmark):
def setup(self):
self.d = np.linspace(0, 100, 100000)

Expand All @@ -17,7 +19,7 @@ def time_fine_binning(self):
np.histogram(self.d, 10000, (0, 100))


class Histogram2D(object):
class Histogram2D(Benchmark):
def setup(self):
self.d = np.linspace(0, 100, 200000).reshape((-1,2))

Expand All @@ -31,7 +33,7 @@ def time_fine_binning(self):
np.histogramdd(self.d, (10000, 10000), ((0, 100), (0, 100)))


class Bincount(object):
class Bincount(Benchmark):
def setup(self):
self.d = np.arange(80000, dtype=np.intp)
self.e = self.d.astype(np.float64)
Expand All @@ -43,7 +45,7 @@ def time_weights(self):
np.bincount(self.d, weights=self.e)


class Median(object):
class Median(Benchmark):
def setup(self):
self.e = np.arange(10000, dtype=np.float32)
self.o = np.arange(10001, dtype=np.float32)
Expand All @@ -67,7 +69,7 @@ def time_odd_small(self):
np.median(self.o[:500], overwrite_input=True)


class Percentile(object):
class Percentile(Benchmark):
def setup(self):
self.e = np.arange(10000, dtype=np.float32)
self.o = np.arange(10001, dtype=np.float32)
Expand All @@ -79,7 +81,7 @@ def time_percentile(self):
np.percentile(self.e, [25, 35, 55, 65, 75])


class Select(object):
class Select(Benchmark):
def setup(self):
self.d = np.arange(20000)
self.e = self.d.copy()
Expand All @@ -93,7 +95,7 @@ def time_select_larger(self):
np.select(self.cond_large, ([self.d, self.e] * 10))


class Sort(object):
class Sort(Benchmark):
def setup(self):
self.e = np.arange(10000, dtype=np.float32)
self.o = np.arange(10001, dtype=np.float32)
Expand Down Expand Up @@ -125,7 +127,7 @@ def time_argsort_random(self):
self.o.argsort()


class SortWorst(object):
class SortWorst(Benchmark):
def setup(self):
# quicksort median of 3 worst case
self.worst = np.arange(1000000)
Expand All @@ -142,7 +144,7 @@ def time_sort_worst(self):
time_sort_worst.benchmark_name = "bench_function_base.Sort.time_sort_worst"


class Where(object):
class Where(Benchmark):
def setup(self):
self.d = np.arange(20000)
self.e = self.d.copy()
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/benchmarks/bench_indexing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function

from .common import get_squares_, get_indexes_, get_indexes_rand_
from .common import Benchmark, get_squares_, get_indexes_, get_indexes_rand_

from os.path import join as pjoin
import shutil
Expand All @@ -11,7 +11,7 @@
from tempfile import mkdtemp


class Indexing(object):
class Indexing(Benchmark):
params = [["indexes_", "indexes_rand_"],
['I', ':,I', 'np.ix_(I, I)'],
['', '=1']]
Expand All @@ -38,7 +38,7 @@ def time_op(self, indexes, sel, op):
self.func()


class IndexingSeparate(object):
class IndexingSeparate(Benchmark):
def setup(self):
self.tmp_dir = mkdtemp()
self.fp = memmap(pjoin(self.tmp_dir, 'tmp.dat'),
Expand All @@ -58,7 +58,7 @@ def time_mmap_fancy_indexing(self):
self.fp[self.indexes]


class IndexingStructured0D(object):
class IndexingStructured0D(Benchmark):
def setup(self):
self.dt = np.dtype([('a', 'f4', 256)])

Expand Down
22 changes: 11 additions & 11 deletions benchmarks/benchmarks/bench_io.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import absolute_import, division, print_function

from .common import get_squares
from .common import Benchmark, get_squares

import numpy as np
from io import StringIO


class Copy(object):
class Copy(Benchmark):
params = ["int8", "int16", "float32", "float64",
"complex64", "complex128"]
param_names = ['type']
Expand Down Expand Up @@ -35,7 +35,7 @@ def time_strided_assign(self, typename):
self.dflat[::2] = 2


class CopyTo(object):
class CopyTo(Benchmark):
def setup(self):
self.d = np.ones(50000)
self.e = self.d.copy()
Expand All @@ -61,14 +61,14 @@ def time_copyto_8_dense(self):
np.copyto(self.d, self.e, where=self.im8)


class Savez(object):
class Savez(Benchmark):
def setup(self):
self.squares = get_squares()

def time_vb_savez_squares(self):
np.savez('tmp.npz', self.squares)

class LoadtxtCSVComments(object):
class LoadtxtCSVComments(Benchmark):
# benchmarks for np.loadtxt comment handling
# when reading in CSV files

Expand Down Expand Up @@ -97,7 +97,7 @@ def time_comment_loadtxt_csv(self, num_lines):
delimiter=u',')
self.data_comments.seek(0)

class LoadtxtCSVdtypes(object):
class LoadtxtCSVdtypes(Benchmark):
# benchmarks for np.loadtxt operating with
# different dtypes parsed / cast from CSV files

Expand All @@ -122,7 +122,7 @@ def time_loadtxt_dtypes_csv(self, dtype, num_lines):
dtype=dtype)
self.csv_data.seek(0)

class LoadtxtCSVStructured(object):
class LoadtxtCSVStructured(Benchmark):
# benchmarks for np.loadtxt operating with
# a structured data type & CSV file

Expand All @@ -145,7 +145,7 @@ def time_loadtxt_csv_struct_dtype(self):
self.csv_data.seek(0)


class LoadtxtCSVSkipRows(object):
class LoadtxtCSVSkipRows(Benchmark):
# benchmarks for loadtxt row skipping when
# reading in csv file data; a similar benchmark
# is present in the pandas asv suite
Expand All @@ -166,7 +166,7 @@ def time_skiprows_csv(self, skiprows):
delimiter=',',
skiprows=skiprows)

class LoadtxtReadUint64Integers(object):
class LoadtxtReadUint64Integers(Benchmark):
# pandas has a similar CSV reading benchmark
# modified to suit np.loadtxt

Expand All @@ -192,7 +192,7 @@ def time_read_uint64_neg_values(self, size):
np.loadtxt(self.data2)
self.data2.seek(0)

class LoadtxtUseColsCSV(object):
class LoadtxtUseColsCSV(Benchmark):
# benchmark selective column reading from CSV files
# using np.loadtxt

Expand All @@ -212,7 +212,7 @@ def time_loadtxt_usecols_csv(self, usecols):
usecols=usecols)
self.csv_data.seek(0)

class LoadtxtCSVDateTime(object):
class LoadtxtCSVDateTime(Benchmark):
# benchmarks for np.loadtxt operating with
# datetime data in a CSV file

Expand Down
8 changes: 5 additions & 3 deletions benchmarks/benchmarks/bench_lib.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""objects for `numpy.lib`."""
"""Benchmarks for `numpy.lib`."""


from __future__ import absolute_import, division, print_function

from .common import Benchmark

import numpy as np


class Pad(object):
"""objects for `numpy.pad`."""
class Pad(Benchmark):
"""Benchmarks for `numpy.pad`."""

param_names = ["shape", "pad_width", "mode"]
params = [
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/benchmarks/bench_linalg.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import absolute_import, division, print_function

from .common import get_squares_, get_indexes_rand, TYPES1
from .common import Benchmark, get_squares_, get_indexes_rand, TYPES1

import numpy as np


class Eindot(object):
class Eindot(Benchmark):
def setup(self):
self.a = np.arange(60000.0).reshape(150, 400)
self.ac = self.a.copy()
Expand Down Expand Up @@ -73,7 +73,7 @@ def time_tensordot_a_b_axes_1_0_0_1(self):
np.tensordot(self.a3, self.b3, axes=([1, 0], [0, 1]))


class Linalg(object):
class Linalg(Benchmark):
params = [['svd', 'pinv', 'det', 'norm'],
TYPES1]
param_names = ['op', 'type']
Expand All @@ -100,7 +100,7 @@ def time_op(self, op, typename):
self.func(self.a)


class Lstsq(object):
class Lstsq(Benchmark):
def setup(self):
self.a = get_squares_()['float64']
self.b = get_indexes_rand()[:100].astype(np.float64)
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/benchmarks/bench_ma.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import, division, print_function

from .common import Benchmark

import numpy as np


class MA(object):
class MA(Benchmark):
def setup(self):
self.l100 = range(100)
self.t100 = ([True] * 100)
Expand All @@ -18,7 +20,7 @@ def time_masked_array_l100_t100(self):
np.ma.masked_array(self.l100, self.t100)


class Indexing(object):
class Indexing(Benchmark):
param_names = ['masked', 'ndim', 'size']
params = [[True, False],
[1, 2],
Expand All @@ -45,7 +47,7 @@ def time_1d(self, masked, ndim, size):
self.m[self.idx_1d]


class UFunc(object):
class UFunc(Benchmark):
param_names = ['a_masked', 'b_masked', 'size']
params = [[True, False],
[True, False],
Expand Down Expand Up @@ -77,7 +79,7 @@ def time_2d(self, a_masked, b_masked, size):
np.ma.add(self.a_2d, self.b_2d)


class Concatenate(object):
class Concatenate(Benchmark):
param_names = ['mode', 'n']
params = [
['ndarray', 'unmasked',
Expand Down
Loading

0 comments on commit c0cf617

Please sign in to comment.