-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarking_sums.qmd
196 lines (138 loc) · 2.77 KB
/
benchmarking_sums.qmd
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
---
title: "Benchmarking"
execute:
warning: true
error: true
keep-ipynb: true
cache: true
jupyter: python3
---
```{python}
import polars as pl
import pandas as pd
import numpy as np
import pyarrow as pa
import plotly.express as px
import string
import random
import os
import sys
%matplotlib inline
import matplotlib.pyplot as plt
from datetime import datetime
import mlx.core as mx
import time
```
```{python}
# Maker an array of floats.
A_numpy = np.random.randn(int(1e6), 10)
A_numpy = A_numpy.copy()
A_polars = pl.DataFrame(A_numpy)
A_pandas_numpy = pd.DataFrame(A_numpy)
A_pandas_arrow = pd.DataFrame(A_numpy, dtype="float32[pyarrow]")
# A_arrow = pa.Table.from_pandas(A_pandas_numpy) # no sum method
A_mlx = mx.array(A_numpy)
```
Candidates currently ommited:
1. JAX
2. PyTorch
3. TensorFlow
4. ?
# Summing Over Columns
```{python}
%timeit -n 4 -r 2 A_numpy.sum(axis=0)
```
```{python}
A_numpy.sum(axis=0).shape
```
```{python}
%timeit -n 4 -r 2 A_polars.sum()
```
```{python}
A_polars.sum().shape
```
```{python}
%timeit -n 4 -r 2 A_mlx.sum(axis=0)
```
```{python}
A_mlx.sum(axis=0).shape
```
## 50 Shades of Pandas
Pandas with numpy backend
```{python}
%timeit -n 4 -r 2 A_pandas_numpy.sum(axis=0)
```
```{python}
A_pandas_numpy.sum(axis=0).shape
```
Pandas with arrow backend
```{python}
%timeit -n 4 -r 2 A_pandas_arrow.sum(axis=0)
```
```{python}
A_pandas_arrow.sum(axis=0).shape
```
Pandas with numpy backend, converted to numpy
```{python}
%timeit -n 4 -r 2 A_pandas_numpy.values.sum(axis=0)
```
```{python}
A_pandas_numpy.values.sum(axis=0).shape
```
Pandas with arrow backend, converted to numpy
```{python}
%timeit -n 4 -r 2 A_pandas_arrow.values.sum(axis=0)
```
```{python}
type(A_pandas_arrow.values)
```
```{python}
A_pandas_arrow.values.sum(axis=0).shape
```
Pandas to mlx
```{python}
%timeit -n 4 -r 2 mx.array(A_pandas_numpy.values).sum(axis=0)
```
```{python}
mx.array(A_pandas_numpy.values).sum(axis=0).shape
```
# Summing Over Rows
```{python}
%timeit -n 4 -r 2 A_numpy.sum(axis=1)
```
```{python}
A_numpy.sum(axis=1).shape
```
```{python}
%timeit -n 4 -r 2 A_polars.sum_horizontal()
```
```{python}
A_polars.sum_horizontal().shape
```
```{python}
%timeit -n 4 -r 2 A_mlx.sum(axis=1)
```
```{python}
A_mlx.sum(axis=1).shape
```
## 50 Shades of Pandas
Pandas with numpy backend
```{python}
%timeit -n 4 -r 2 A_pandas_numpy.sum(axis=1)
```
Pandas with arrow backend
```{python}
%timeit -n 4 -r 2 A_pandas_arrow.sum(axis=1)
```
Pandas with numpy backend, converted to numpy
```{python}
%timeit -n 4 -r 2 A_pandas_numpy.values.sum(axis=1)
```
Pandas with arrow backend, converted to numpy
```{python}
%timeit -n 4 -r 2 A_pandas_arrow.values.sum(axis=1)
```
Pandas to mlx
```{python}
%timeit -n 4 -r 2 mx.array(A_pandas_numpy.values).sum(axis=1)
```