This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,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) |
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,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) |
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,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) |
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,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) |