1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
import numpy as np
from cykhash import unique_int64, unique_int32, unique_float64, unique_float32
from cykhash import unique_stable_int64, unique_stable_int32, unique_stable_float64, unique_stable_float32
UNIQUE={
np.float64 : unique_float64,
np.float32 : unique_float32,
np.int64 : unique_int64,
np.int32 : unique_int32,
}
UNIQUE_STABLE = {
np.float64 : unique_stable_float64,
np.float32 : unique_stable_float32,
np.int64 : unique_stable_int64,
np.int32 : unique_stable_int32,
}
class UniqueArange:
params = [
[np.float64, np.float32, np.int64, np.int32],
[1_000, 2_000, 8_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
self.array = np.arange(M, dtype=dtype)
def time_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def time_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
def peakmem_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def peakmem_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
class UniqueRandomDivFactor10:
params = [
[np.float64, np.float32, np.int64, np.int32],
[1_000, 2_000, 8_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
np.random.seed(42)
self.array = np.random.randint(0, M//10, M).astype(dtype)
def time_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def time_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
def peakmem_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def peakmem_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
class UniqueRandomDivFactor10Add220:
params = [
[np.float64, np.float32, np.int64, np.int32],
[1_000, 2_000, 8_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
np.random.seed(42)
self.array = (np.random.randint(0, M//10, M)+2**26).astype(dtype)
def time_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def time_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
class UniqueRandomMulFactor10:
params = [
[np.float64, np.float32, np.int64, np.int32],
[1_000, 2_000, 8_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
np.random.seed(42)
self.array = np.random.randint(0, M*10, M).astype(dtype)
def time_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def time_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
class UniqueSingle:
params = [
[np.float64, np.float32, np.int64, np.int32],
[10_000_000, 100_000_000],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
self.array = np.ones(M, dtype=dtype)
def peakmem_unique(self, dtype, M):
UNIQUE[dtype](self.array)
def peakmem_unique_stable(self, dtype, M):
UNIQUE_STABLE[dtype](self.array)
|