-
Notifications
You must be signed in to change notification settings - Fork 12
/
perf.py
58 lines (53 loc) · 1.41 KB
/
perf.py
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
import timeit
import warnings
import numpy as np
setup = """
import pandas as pd
import polars as pl
import minimal_plugin # noqa: F401
import numpy as np
rng = np.random.default_rng(12345)
N = 10_000_000
df = pl.DataFrame({'a': rng.integers(low=-100, high=100, size=N)})
df = df.with_row_index().with_columns(
pl.when(pl.col('index')%2==1).then(pl.lit(None)).otherwise(pl.col('a')).alias('a')
)
"""
results = (
np.array(
timeit.Timer(
stmt="df.select(pl.col('a').mp.abs_i64_fast())",
setup=setup,
).repeat(7, 3)
)
/ 3
)
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"{np.mean(results)} +/- {np.std(results)/np.sqrt(len(results))}")
results = (
np.array(
timeit.Timer(
stmt="df.select(pl.col('a').mp.abs_i64())",
setup=setup,
).repeat(7, 3)
)
/ 3
)
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"{np.mean(results)} +/- {np.std(results)/np.sqrt(len(results))}")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
results = (
np.array(
timeit.Timer(
stmt="df.select(pl.col('a').map_elements(lambda x: abs(x)))",
setup=setup,
).repeat(7, 3)
)
/ 3
)
print(f"min: {min(results)}")
print(f"max: {max(results)}")
print(f"{np.mean(results)} +/- {np.std(results)/np.sqrt(len(results))}")