Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge b133b3d into 5fba799
Browse files Browse the repository at this point in the history
  • Loading branch information
densmirn committed Aug 30, 2019
2 parents 5fba799 + b133b3d commit 6701c30
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
Empty file added tests_perf/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests_perf/algorithms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from .common import Implementation, ImplRunner
from .data_generator import DataGenerator


class Quantile():
params = [[0.5],
['linear', 'nearest', 'lower', 'higher', 'midpoint'],
['float', 'int', 'uint'],
[Implementation.native.value, Implementation.hpat.value]]
pparam_names = ['quantile', 'interpolation', 'dtype', 'implementation']

def setup(self, quantile, interpolation, dtype, implementation):
N = 10 ** 7
data_generator = DataGenerator()
data = {
'int': data_generator.make_int_series(N, repeat=5),
'uint': data_generator.make_uint_series(N, repeat=5),
'float': data_generator.make_float_series(N, repeat=5),
}
self.idx = data[dtype]

def time_quantile(self, quantile, interpolation, dtype, implementation):
def _quantile(idx, quantile, interpolation=interpolation):
return idx.quantile(quantile, interpolation=interpolation)
ImplRunner(implementation, _quantile).run(self.idx, quantile, interpolation=interpolation)
31 changes: 31 additions & 0 deletions tests_perf/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from enum import Enum

import numba

import hpat


class Implementation(Enum):
native = 'native'
njit = 'njit'
hpat = 'hpat'


class ImplRunner:
def __init__(self, implementation, func):
self.implementation = implementation
self.func = func

@property
def runner(self):
if self.implementation == Implementation.hpat.value:
return hpat.jit(self.func)
elif self.implementation == Implementation.njit.value:
return numba.njit(self.func)
elif self.implementation == Implementation.native.value:
return self.func

raise ValueError(f'Unknown implementation: {self.implementation}')

def run(self, *args, **kwargs):
return self.runner(*args, **kwargs)
29 changes: 29 additions & 0 deletions tests_perf/data_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
import pandas as pd

from numpy.random import randn
from pandas.util import testing as tm


class DataGenerator:
def __init__(self):
pass

def randu(self, length):
"""Generate one random unicode string."""
return tm.randu(length)

def make_int_series(self, length, repeat=1, index=None, name=None):
"""Generate series with float range."""
data = pd.Int64Index(np.arange(length)).repeat(repeat)
return pd.Series(data, index=index, name=name)

def make_uint_series(self, length, repeat=1, index=None, name=None):
"""Generate series with unsigned integers range."""
data = pd.UInt64Index(np.arange(length)).repeat(repeat)
return pd.Series(data, index=index, name=name)

def make_float_series(self, length, repeat=1, index=None, name=None):
"""Generate series with random integers."""
data = pd.Float64Index(randn(length)).repeat(repeat)
return pd.Series(data, index=index, name=name)
33 changes: 33 additions & 0 deletions tests_perf/unicode_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from .common import Implementation, ImplRunner
from .data_generator import DataGenerator


class Methods:
params = [Implementation.native.value, Implementation.njit.value]
param_names = ['implementation']

def setup(self, implementation):
N = 10 ** 4
data_generator = DataGenerator()
self.s = data_generator.randu(N)


class WidthMethods(Methods):
def setup(self, implementation):
super().setup(implementation)
self.width = 10 ** 8

def time_center(self, implementation):
def _center(s, width):
return s.center(width)
ImplRunner(implementation, _center).run(self.s, self.width)

def time_ljust(self, implementation):
def _ljust(s, width):
return s.ljust(width)
ImplRunner(implementation, _ljust).run(self.s, self.width)

def time_rjust(self, implementation):
def _rjust(s, width):
return s.ljust(width)
ImplRunner(implementation, _rjust).run(self.s, self.width)

0 comments on commit 6701c30

Please sign in to comment.