-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
347 lines (254 loc) · 8.5 KB
/
Makefile
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# Version 0.2.2
all: versions init benchmarks
versions:
pxi --version
#
gawk --version | head -1
#
jq --version
#
mlr --version
#
-fx --version
#
init: data/2019-small.jsonl data/2019-big.jsonl data/2019-small.csv data/2019-big.csv
data/2019-small.jsonl:
#
# Initializing data files. This is done only once and may take a while!
#
mkdir -p data
touch data/2019-small.jsonl
for ((i=1546300800;i<=1577836799;i++)); do printf '{"time":%d}\n' $$i >> data/2019-small.jsonl; done
data/2019-big.jsonl: data/2019-small.jsonl
pxi "({time}) => { const d = new Date(time * 1000); return {time, year: d.getFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(), hours: d.getUTCHours(), minutes: d.getUTCMinutes(), seconds: d.getUTCSeconds()} }" < data/2019-small.jsonl > data/2019-big.jsonl
data/2019-small.csv: data/2019-small.jsonl
pxi --to csv < data/2019-small.jsonl > data/2019-small.csv
data/2019-big.csv: data/2019-big.jsonl
pxi --to csv < data/2019-big.jsonl > data/2019-big.csv
clean:
rm -rf data
benchmarks: json json2csv csv csv2json
json: json-1 json-2 json-3 json-4
json-1: json-1-pxi json-1-gawk json-1-jq json-1-fx
json-1-pxi:
#
# json-1: Select an attribute on small JSON objects
#
/usr/bin/time -lp pxi 'json => json.time' < data/2019-small.jsonl > /tmp/pxi.jsonl
#
json-1-gawk:
/usr/bin/time -lp gawk -F ':|}' '{print $$2}' < data/2019-small.jsonl > /tmp/gawk.jsonl
#
diff --brief --report-identical-files /tmp/gawk.jsonl /tmp/pxi.jsonl
#
json-1-jq:
/usr/bin/time -lp jq '.time' < data/2019-small.jsonl > /tmp/jq.jsonl
#
diff --brief --report-identical-files /tmp/jq.jsonl /tmp/pxi.jsonl
#
json-1-fx:
/usr/bin/time -lp fx 'json => json.time' < data/2019-small.jsonl > /tmp/fx.jsonl
#
diff --brief --report-identical-files /tmp/fx.jsonl /tmp/pxi.jsonl
#
json-2: json-2-pxi json-2-gawk json-2-jq json-2-fx
json-2-pxi:
#
# json-2: Select an attribute on large JSON objects
#
/usr/bin/time -lp pxi 'json => json.time' < data/2019-big.jsonl > /tmp/pxi.jsonl
#
json-2-gawk:
/usr/bin/time -lp gawk -F ':|,' '{print $$2}' < data/2019-big.jsonl > /tmp/gawk.jsonl
#
diff --brief --report-identical-files /tmp/gawk.jsonl /tmp/pxi.jsonl
#
json-2-jq:
/usr/bin/time -lp jq '.time' < data/2019-big.jsonl > /tmp/jq.jsonl
#
diff --brief --report-identical-files /tmp/jq.jsonl /tmp/pxi.jsonl
#
json-2-fx:
/usr/bin/time -lp fx 'json => json.time' < data/2019-big.jsonl > /tmp/fx.jsonl
#
diff --brief --report-identical-files /tmp/fx.jsonl /tmp/pxi.jsonl
#
json-3: json-3-pxi json-3-gawk json-3-mlr json-3-jq json-3-fx
json-3-pxi:
#
# json-3: Pick a single attribute on small JSON objects
#
/usr/bin/time -lp pxi '({time}) => ({time})' < data/2019-small.jsonl > /tmp/pxi.jsonl
#
json-3-gawk:
/usr/bin/time -lp gawk -F ':|}' '{print "{\"time\":"$$2"}"}' < data/2019-small.jsonl > /tmp/gawk.jsonl
#
diff --brief --report-identical-files /tmp/gawk.jsonl /tmp/pxi.jsonl
#
json-3-mlr:
#
/usr/bin/time -lp mlr --json cut -f time < data/2019-small.jsonl > /tmp/mlr.jsonl
#
pxi < /tmp/mlr.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json-3-jq:
/usr/bin/time -lp jq -c '{time:.time}' < data/2019-small.jsonl > /tmp/jq.jsonl
#
pxi -c jsonObj < /tmp/jq.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json-3-fx:
/usr/bin/time -lp fx '({time}) => ({time})' < data/2019-small.jsonl > /tmp/fx.jsonl
#
pxi -c jsonObj < /tmp/fx.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json-4: json-4-pxi json-4-gawk json-4-mlr json-4-jq json-4-fx
json-4-pxi:
#
# json-4: Pick a single attribute on large JSON objects
#
/usr/bin/time -lp pxi '({time}) => ({time})' < data/2019-big.jsonl > /tmp/pxi.jsonl
#
json-4-gawk:
/usr/bin/time -lp gawk -F ':|,' '{print "{\"time\":"$$2"}"}' < data/2019-big.jsonl > /tmp/gawk.jsonl
#
diff --brief --report-identical-files /tmp/gawk.jsonl /tmp/pxi.jsonl
#
json-4-mlr:
#
# For reasons unknown to me, mlr fails without error on the whole input file.
# This is why 20,000,000 lines are processed first, followed by the remaining lines.
#
head -20000000 data/2019-big.jsonl | /usr/bin/time -lp mlr --json cut -f time > /tmp/mlr.jsonl
tail +20000001 data/2019-big.jsonl | /usr/bin/time -lp mlr --json cut -f time >> /tmp/mlr.jsonl
#
pxi < /tmp/mlr.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json-4-jq:
/usr/bin/time -lp jq -c '{time:.time}' < data/2019-big.jsonl > /tmp/jq.jsonl
#
pxi -c jsonObj < /tmp/jq.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json-4-fx:
/usr/bin/time -lp fx '({time}) => ({time})' < data/2019-big.jsonl > /tmp/fx.jsonl
#
pxi -c jsonObj < /tmp/fx.jsonl | diff --brief --report-identical-files - /tmp/pxi.jsonl
#
json2csv: json2csv-1 json2csv-2
json2csv-1: json2csv-1-pxi json2csv-1-mlr json2csv-1-jq
json2csv-1-pxi:
#
# json2csv-1: Convert a small JSON to CSV format
#
/usr/bin/time -lp pxi --to csv < data/2019-small.jsonl > /tmp/pxi.csv
#
json2csv-1-mlr:
#
/usr/bin/time -lp mlr --j2c filter 'true' < data/2019-small.jsonl > /tmp/mlr.csv
#
diff --brief --report-identical-files /tmp/mlr.csv /tmp/pxi.csv
#
json2csv-1-jq:
/usr/bin/time -lp jq -r '[.[]] | @csv' < data/2019-small.jsonl > /tmp/jq.csv
#
tail +2 /tmp/pxi.csv | diff --brief --report-identical-files - /tmp/jq.csv
#
json2csv-2: json2csv-2-pxi json2csv-2-mlr json2csv-2-jq
json2csv-2-pxi:
#
# json2csv-2: Convert a large JSON to CSV format
#
/usr/bin/time -lp pxi --to csv < data/2019-big.jsonl > /tmp/pxi.csv
#
json2csv-2-mlr:
#
# For reasons unknown to me, mlr fails without error on the whole input file.
# This is why 20,000,000 lines are processed first, followed by the remaining lines.
#
head -20000000 data/2019-big.jsonl | /usr/bin/time -lp mlr --j2c filter 'true' > /tmp/mlr.csv
tail +20000001 data/2019-big.jsonl | /usr/bin/time -lp mlr --headerless-csv-output --j2c filter 'true' >> /tmp/mlr.csv
#
diff --brief --report-identical-files /tmp/mlr.csv /tmp/pxi.csv
#
json2csv-2-jq:
/usr/bin/time -lp jq -r '[.[]] | @csv' < data/2019-big.jsonl > /tmp/jq.csv
#
tail +2 /tmp/pxi.csv | diff --brief --report-identical-files - /tmp/jq.csv
#
csv: csv-1 csv-2
csv-1: csv-1-pxi csv-1-jq csv-1-gawk csv-1-mlr
csv-1-pxi:
#
# csv-1: Select a column from a small csv file
#
/usr/bin/time -lp pxi '({time}) => ({time})' --from csv --to csv < data/2019-small.csv > /tmp/pxi.csv
#
csv-1-mlr:
/usr/bin/time -lp mlr --csv --rs '\n' --fs , cut -f time < data/2019-small.csv > /tmp/mlr.csv
#
diff --brief --report-identical-files /tmp/mlr.csv /tmp/pxi.csv
#
csv-1-gawk:
/usr/bin/time -lp gawk -F , '{print $$1}' < data/2019-small.csv > /tmp/gawk.csv
#
diff --brief --report-identical-files /tmp/gawk.csv /tmp/pxi.csv
#
csv-1-jq:
/usr/bin/time -lp jq -crR 'split(",") | .[0]' < data/2019-small.csv > /tmp/jq.csv
#
diff --brief --report-identical-files /tmp/jq.csv /tmp/pxi.csv
#
csv-2: csv-2-pxi csv-2-jq csv-2-gawk csv-2-mlr
csv-2-pxi:
#
# csv-2: Select a column from a large csv file
#
/usr/bin/time -lp pxi '({month}) => ({month})' --from csv --to csv < data/2019-big.csv > /tmp/pxi.csv
#
csv-2-mlr:
/usr/bin/time -lp mlr --csv --rs '\n' --fs , cut -f month < data/2019-big.csv > /tmp/mlr.csv
#
diff --brief --report-identical-files /tmp/mlr.csv /tmp/pxi.csv
#
csv-2-gawk:
/usr/bin/time -lp gawk -F , '{print $$3}' < data/2019-big.csv > /tmp/gawk.csv
#
diff --brief --report-identical-files /tmp/gawk.csv /tmp/pxi.csv
#
csv-2-jq:
/usr/bin/time -lp jq -crR 'split(",") | .[2]' < data/2019-big.csv > /tmp/jq.csv
#
diff --brief --report-identical-files /tmp/jq.csv /tmp/pxi.csv
#
csv2json: csv2json-1 csv2json-2
csv2json-1: csv2json-1-pxi csv2json-1-mlr
csv2json-1-pxi:
#
# csv2json-1: Convert a small CSV to JSON format
#
/usr/bin/time -lp pxi --from csv < data/2019-small.csv > /tmp/pxi.jsonl
#
csv2json-1-mlr:
#
/usr/bin/time -lp mlr --c2j filter 'true' < data/2019-small.csv > /tmp/mlr.jsonl
#
pxi '({time}) => ({time: time.toString()})' < /tmp/mlr.jsonl | diff --brief --report-identical-files /tmp/pxi.jsonl -
#
csv2json-2: csv2json-2-pxi csv2json-2-mlr
csv2json-2-pxi:
#
# csv2json-2: Convert a large CSV to JSON format
#
/usr/bin/time -lp pxi --from csv < data/2019-big.csv > /tmp/pxi.jsonl
#
csv2json-2-mlr:
#
/usr/bin/time -lp mlr --c2j filter 'true' < data/2019-big.csv > /tmp/mlr.jsonl
#
pxi 'json => Object.keys(json).reduce((o, k) => ({...o, [k]: json[k].toString()}), {})' < /tmp/mlr.jsonl | diff --brief --report-identical-files /tmp/pxi.jsonl -
#
ssv: ssv-1
ssv-1: ssv-1-desc ssv-1-pxi ssv-1-gawk ssv-1-diff
ssv-1-desc:
#
# ssv-1:
#