fat_table 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-with-dbs.yml +2 -2
- data/CHANGELOG.md +88 -76
- data/CHANGELOG.org +8 -0
- data/README.md +117 -117
- data/README.org +24 -24
- data/benchmark/README.org +238 -0
- data/benchmark/column-baseline-10000.jsonl +5 -0
- data/benchmark/column-fast-10000.jsonl +5 -0
- data/benchmark/column.rb +59 -0
- data/benchmark/formatting-baseline-4000.jsonl +3 -0
- data/benchmark/formatting-buffer-4000.jsonl +3 -0
- data/benchmark/insertion-baseline-1000.jsonl +3 -0
- data/benchmark/insertion-direct-1000.jsonl +3 -0
- data/benchmark/insertion.rb +55 -0
- data/benchmark/joins-baseline-200.jsonl +3 -0
- data/benchmark/joins-indexed-200.jsonl +3 -0
- data/benchmark/joins.rb +87 -0
- data/benchmark/sort-baseline-4000.jsonl +3 -0
- data/benchmark/sort-prepared-4000.jsonl +3 -0
- data/benchmark/sort.rb +57 -0
- data/benchmark/transform_and_render.rb +52 -0
- data/lib/fat_table/column.rb +17 -3
- data/lib/fat_table/convert.rb +6 -0
- data/lib/fat_table/formatters/formatter.rb +13 -13
- data/lib/fat_table/table.rb +115 -39
- data/lib/fat_table/version.rb +1 -1
- data/scripts/benchmark-column +17 -0
- data/scripts/benchmark-compare +105 -0
- data/scripts/benchmark-formatting +17 -0
- data/scripts/benchmark-insertion +17 -0
- data/scripts/benchmark-joins +17 -0
- data/scripts/benchmark-sort +17 -0
- metadata +24 -2
data/lib/fat_table/column.rb
CHANGED
|
@@ -457,8 +457,8 @@ module FatTable
|
|
|
457
457
|
# Append +itm+ to end of the Column after converting it to the Column's
|
|
458
458
|
# type. If the Column's type is still open, i.e. NilClass, attempt to fix
|
|
459
459
|
# the Column's type based on the type of +itm+ as with Column.new. If its
|
|
460
|
-
# a tolerant column,
|
|
461
|
-
#
|
|
460
|
+
# a tolerant column, store incompatible values as strings while retaining
|
|
461
|
+
# the Column's declared type.
|
|
462
462
|
def <<(itm)
|
|
463
463
|
items << convert_and_set_type(itm)
|
|
464
464
|
rescue IncompatibleTypeError => ex
|
|
@@ -484,13 +484,27 @@ module FatTable
|
|
|
484
484
|
private
|
|
485
485
|
|
|
486
486
|
def convert_and_set_type(val)
|
|
487
|
+
# Established columns can accept compatible native values directly.
|
|
488
|
+
# Floats still need promotion to BigDecimal, and open columns still infer
|
|
489
|
+
# their type through the normal conversion path.
|
|
490
|
+
case type
|
|
491
|
+
when 'String'
|
|
492
|
+
return val.nil? ? nil : Convert.convert_to_string(val)
|
|
493
|
+
when 'Numeric'
|
|
494
|
+
return val if val.is_a?(Numeric) && !val.is_a?(Float)
|
|
495
|
+
when 'DateTime'
|
|
496
|
+
return val if val.is_a?(Date)
|
|
497
|
+
when 'Boolean'
|
|
498
|
+
return val if val.equal?(true) || val.equal?(false)
|
|
499
|
+
end
|
|
500
|
+
|
|
487
501
|
begin
|
|
488
502
|
new_val = Convert.convert_to_type(val, type, tolerant: tolerant?)
|
|
489
503
|
rescue IncompatibleTypeError
|
|
490
504
|
err_msg = "attempt to add '#{val}' to column '#{header}' already typed as #{type}"
|
|
491
505
|
raise IncompatibleTypeError, err_msg
|
|
492
506
|
end
|
|
493
|
-
if new_val &&
|
|
507
|
+
if new_val && type == 'NilClass'
|
|
494
508
|
@type =
|
|
495
509
|
if [true, false].include?(new_val)
|
|
496
510
|
'Boolean'
|
data/lib/fat_table/convert.rb
CHANGED
|
@@ -38,6 +38,8 @@ module FatTable
|
|
|
38
38
|
else
|
|
39
39
|
new_val = convert_to_boolean(val)
|
|
40
40
|
if new_val.nil?
|
|
41
|
+
return convert_to_string(val) if tolerant
|
|
42
|
+
|
|
41
43
|
raise IncompatibleTypeError
|
|
42
44
|
end
|
|
43
45
|
|
|
@@ -49,6 +51,8 @@ module FatTable
|
|
|
49
51
|
else
|
|
50
52
|
new_val = convert_to_date_time(val)
|
|
51
53
|
if new_val.nil?
|
|
54
|
+
return convert_to_string(val) if tolerant
|
|
55
|
+
|
|
52
56
|
raise IncompatibleTypeError
|
|
53
57
|
end
|
|
54
58
|
|
|
@@ -60,6 +64,8 @@ module FatTable
|
|
|
60
64
|
else
|
|
61
65
|
new_val = convert_to_numeric(val)
|
|
62
66
|
if new_val.nil?
|
|
67
|
+
return convert_to_string(val) if tolerant
|
|
68
|
+
|
|
63
69
|
raise IncompatibleTypeError
|
|
64
70
|
end
|
|
65
71
|
|
|
@@ -1174,36 +1174,36 @@ module FatTable
|
|
|
1174
1174
|
# any event, the result is a single string (or ruby object if eval is true
|
|
1175
1175
|
# for the Formatter) representing the table in the syntax of the output
|
|
1176
1176
|
# target.
|
|
1177
|
-
result = ''
|
|
1178
|
-
result
|
|
1177
|
+
result = +''
|
|
1178
|
+
result << pre_table
|
|
1179
1179
|
if include_header_row?
|
|
1180
|
-
result
|
|
1181
|
-
result
|
|
1180
|
+
result << pre_header(widths)
|
|
1181
|
+
result << pre_row
|
|
1182
1182
|
cells = []
|
|
1183
1183
|
formatted_headers.each_pair do |h, (_v, fmt_v)|
|
|
1184
1184
|
cells << pre_cell(h) + quote_cell(fmt_v) + post_cell
|
|
1185
1185
|
end
|
|
1186
|
-
result
|
|
1187
|
-
result
|
|
1188
|
-
result
|
|
1186
|
+
result << cells.join(inter_cell)
|
|
1187
|
+
result << post_row
|
|
1188
|
+
result << post_header(widths)
|
|
1189
1189
|
end
|
|
1190
1190
|
new_rows.each do |loc_row|
|
|
1191
1191
|
if loc_row.nil?
|
|
1192
|
-
result
|
|
1192
|
+
result << hline(widths)
|
|
1193
1193
|
next
|
|
1194
1194
|
end
|
|
1195
1195
|
|
|
1196
1196
|
_loc, row = *loc_row
|
|
1197
|
-
result
|
|
1197
|
+
result << pre_row
|
|
1198
1198
|
cells = []
|
|
1199
1199
|
row.each_pair do |h, (_v, fmt_v)|
|
|
1200
1200
|
cells << pre_cell(h) + quote_cell(fmt_v) + post_cell
|
|
1201
1201
|
end
|
|
1202
|
-
result
|
|
1203
|
-
result
|
|
1202
|
+
result << cells.join(inter_cell)
|
|
1203
|
+
result << post_row
|
|
1204
1204
|
end
|
|
1205
|
-
result
|
|
1206
|
-
result
|
|
1205
|
+
result << post_footers(widths)
|
|
1206
|
+
result << post_table
|
|
1207
1207
|
|
|
1208
1208
|
# If this Formatter targets a ruby data structure (e.g., AoaFormatter), we
|
|
1209
1209
|
# eval the string to get the object.
|
data/lib/fat_table/table.rb
CHANGED
|
@@ -829,33 +829,20 @@ module FatTable
|
|
|
829
829
|
# After sorting, the output Table will have group boundaries added after
|
|
830
830
|
# each row where the sort key changes.
|
|
831
831
|
def order_by(*sort_heads)
|
|
832
|
-
#
|
|
832
|
+
# Prepare raw grouping keys and normalized comparison keys once per row.
|
|
833
833
|
key_hash = partition_sort_keys(sort_heads)
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
else
|
|
843
|
-
key1 << r2[h]
|
|
844
|
-
key2 << r1[h]
|
|
845
|
-
end
|
|
846
|
-
end
|
|
847
|
-
# Make any booleans comparable with <=>
|
|
848
|
-
key1 = key1.map_booleans
|
|
849
|
-
key2 = key2.map_booleans
|
|
850
|
-
|
|
851
|
-
# If there are any nils, <=> will return nil, and we have to use the
|
|
852
|
-
# special comparison method, compare_with_nils, instead.
|
|
853
|
-
result = (key1 <=> key2)
|
|
854
|
-
result = compare_with_nils(key1, key2) if result.nil?
|
|
834
|
+
heads = key_hash.keys
|
|
835
|
+
directions = key_hash.values
|
|
836
|
+
prepared_rows = rows.each_with_index.map do |row, index|
|
|
837
|
+
key = row.fetch_values(*heads)
|
|
838
|
+
[row, index, key, key.map_booleans]
|
|
839
|
+
end
|
|
840
|
+
prepared_rows.sort! do |(_, index1, _, key1), (_, index2, _, key2)|
|
|
841
|
+
result = compare_prepared_sort_keys(key1, key2, directions)
|
|
855
842
|
result.zero? ? index1 <=> index2 : result
|
|
856
|
-
|
|
843
|
+
end
|
|
857
844
|
|
|
858
|
-
# Add the
|
|
845
|
+
# Add the sorted rows to the table, but mark a group boundary at the points
|
|
859
846
|
# where the sort key changes value. NB: I use self.class.new here
|
|
860
847
|
# rather than Table.new because if this class is inherited, I want the
|
|
861
848
|
# new_tab to be an instance of the subclass. With Table.new, this
|
|
@@ -863,9 +850,8 @@ module FatTable
|
|
|
863
850
|
# the subclass.
|
|
864
851
|
new_tab = empty_dup
|
|
865
852
|
last_key = nil
|
|
866
|
-
|
|
853
|
+
prepared_rows.each_with_index do |(nrow, _, key, _), k|
|
|
867
854
|
new_tab << nrow
|
|
868
|
-
key = nrow.fetch_values(*key_hash.keys)
|
|
869
855
|
new_tab.mark_boundary(k - 1) if last_key && key != last_key
|
|
870
856
|
last_key = key
|
|
871
857
|
end
|
|
@@ -1014,12 +1000,14 @@ module FatTable
|
|
|
1014
1000
|
end
|
|
1015
1001
|
result = empty_dup(result_cols)
|
|
1016
1002
|
normalize_boundaries
|
|
1003
|
+
group_boundaries = boundaries
|
|
1004
|
+
group_index = 0
|
|
1017
1005
|
|
|
1018
1006
|
rows.each_with_index do |old_row, old_k|
|
|
1019
1007
|
# Set the group number in the before hook and run the hook with the
|
|
1020
1008
|
# local variables set to the row before the new row is evaluated.
|
|
1021
|
-
|
|
1022
|
-
ev.update_ivars(row: old_k + 1, group:
|
|
1009
|
+
group_index += 1 while old_k > group_boundaries[group_index]
|
|
1010
|
+
ev.update_ivars(row: old_k + 1, group: group_index + 1)
|
|
1023
1011
|
ev.eval_before_hook(locals: old_row)
|
|
1024
1012
|
# Compute the new row.
|
|
1025
1013
|
new_row = {}
|
|
@@ -1086,9 +1074,11 @@ module FatTable
|
|
|
1086
1074
|
expr = expr.to_s
|
|
1087
1075
|
result = empty_dup
|
|
1088
1076
|
ev = Evaluator.new(ivars: { row: 0, group: 0 })
|
|
1077
|
+
group_boundaries = boundaries
|
|
1078
|
+
group_index = 0
|
|
1089
1079
|
rows.each_with_index do |row, k|
|
|
1090
|
-
|
|
1091
|
-
ev.update_ivars(row: k + 1, group:
|
|
1080
|
+
group_index += 1 while k > group_boundaries[group_index]
|
|
1081
|
+
ev.update_ivars(row: k + 1, group: group_index + 1)
|
|
1092
1082
|
ev.eval_before_hook(locals: row)
|
|
1093
1083
|
result << row if ev.evaluate(expr, locals: row)
|
|
1094
1084
|
ev.eval_after_hook(locals: row)
|
|
@@ -1285,15 +1275,24 @@ module FatTable
|
|
|
1285
1275
|
build_join_expression(exps, other, join_type)
|
|
1286
1276
|
ev = Evaluator.new
|
|
1287
1277
|
result = empty_dup
|
|
1278
|
+
self_rows = rows
|
|
1288
1279
|
other_rows = other.rows
|
|
1280
|
+
key_columns = join_key_columns(exps, other, join_type)
|
|
1281
|
+
join_index = build_join_index(key_columns, self_rows, other_rows)
|
|
1282
|
+
all_indices = (0...other_rows.size).to_a unless join_index
|
|
1289
1283
|
other_row_matches = Array.new(other_rows.size, false)
|
|
1290
|
-
|
|
1284
|
+
self_rows.each_with_index do |self_row, row_index|
|
|
1291
1285
|
self_row_matched = false
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1286
|
+
candidates = join_index ? join_index[1].fetch(join_index[0][row_index], []) : all_indices
|
|
1287
|
+
candidates.each do |k|
|
|
1288
|
+
other_row = other_rows[k]
|
|
1289
|
+
matches =
|
|
1290
|
+
if join_index
|
|
1291
|
+
key_columns.all? { |a, b| self_row[a] == other_row[b] }
|
|
1292
|
+
else
|
|
1293
|
+
locals = build_locals_hash(row_a: self_row, row_b: other_row)
|
|
1294
|
+
ev.evaluate(join_exp, locals: locals)
|
|
1295
|
+
end
|
|
1297
1296
|
next unless matches
|
|
1298
1297
|
|
|
1299
1298
|
self_row_matched = other_row_matches[k] = true
|
|
@@ -1354,6 +1353,69 @@ module FatTable
|
|
|
1354
1353
|
|
|
1355
1354
|
private
|
|
1356
1355
|
|
|
1356
|
+
# Only index explicit equality conditions. The expression builder above
|
|
1357
|
+
# remains responsible for validation and output-column selection.
|
|
1358
|
+
def join_key_columns(exps, other, type)
|
|
1359
|
+
return if type == :cross || exps.any? { |exp| !exp.is_a?(Symbol) }
|
|
1360
|
+
return (headers & other.headers).map { |head| [head, head] } if exps.empty?
|
|
1361
|
+
|
|
1362
|
+
pairs = []
|
|
1363
|
+
pending = nil
|
|
1364
|
+
exps.each do |exp|
|
|
1365
|
+
match = /\A(.*)_([ab])\z/.match(exp.to_s.clean)
|
|
1366
|
+
if match
|
|
1367
|
+
head = match[1].to_sym
|
|
1368
|
+
side = match[2]
|
|
1369
|
+
if pending
|
|
1370
|
+
return nil if pending[1] == side
|
|
1371
|
+
|
|
1372
|
+
pairs << (side == 'b' ? [pending[0], head] : [head, pending[0]])
|
|
1373
|
+
pending = nil
|
|
1374
|
+
else
|
|
1375
|
+
pending = [head, side]
|
|
1376
|
+
end
|
|
1377
|
+
else
|
|
1378
|
+
return nil if pending
|
|
1379
|
+
|
|
1380
|
+
pairs << [exp, exp]
|
|
1381
|
+
end
|
|
1382
|
+
end
|
|
1383
|
+
pairs unless pending
|
|
1384
|
+
end
|
|
1385
|
+
|
|
1386
|
+
# Hash equality is stricter than == for mixed numbers and dates. Normalize
|
|
1387
|
+
# supported built-in values, then recheck == on candidate rows (notably NaN).
|
|
1388
|
+
# Unusual Numeric objects and subclasses retain the original evaluator path.
|
|
1389
|
+
def join_hash_key(row, heads)
|
|
1390
|
+
heads.map do |head|
|
|
1391
|
+
value = row[head]
|
|
1392
|
+
if value.instance_of?(Integer)
|
|
1393
|
+
value.to_r
|
|
1394
|
+
elsif value.instance_of?(BigDecimal)
|
|
1395
|
+
value.finite? ? value.to_r : value.to_s
|
|
1396
|
+
elsif value.instance_of?(Date) || value.instance_of?(DateTime)
|
|
1397
|
+
value.ajd
|
|
1398
|
+
elsif [NilClass, TrueClass, FalseClass, String].include?(value.class)
|
|
1399
|
+
value
|
|
1400
|
+
else
|
|
1401
|
+
return nil
|
|
1402
|
+
end
|
|
1403
|
+
end
|
|
1404
|
+
end
|
|
1405
|
+
|
|
1406
|
+
def build_join_index(key_columns, self_rows, other_rows)
|
|
1407
|
+
return unless key_columns
|
|
1408
|
+
|
|
1409
|
+
left_heads, right_heads = key_columns.transpose
|
|
1410
|
+
left_keys = self_rows.map { |row| join_hash_key(row, left_heads) }
|
|
1411
|
+
right_keys = other_rows.map { |row| join_hash_key(row, right_heads) }
|
|
1412
|
+
return if left_keys.any?(&:nil?) || right_keys.any?(&:nil?)
|
|
1413
|
+
|
|
1414
|
+
index = {}
|
|
1415
|
+
right_keys.each_with_index { |key, k| (index[key] ||= []) << k }
|
|
1416
|
+
[left_keys, index]
|
|
1417
|
+
end
|
|
1418
|
+
|
|
1357
1419
|
# Return an output row appropriate to the given join type, including all the
|
|
1358
1420
|
# keys of row_a, the non-common keys of row_b for an :inner join, or all the
|
|
1359
1421
|
# keys of row_b for other joins. If any of the row_b keys are also row_a
|
|
@@ -1572,9 +1634,9 @@ module FatTable
|
|
|
1572
1634
|
items = Array.new(size, nil)
|
|
1573
1635
|
columns << Column.new(header: h, items: items, tolerant: tolerant_col?(h))
|
|
1574
1636
|
end
|
|
1575
|
-
|
|
1576
|
-
#
|
|
1577
|
-
|
|
1637
|
+
columns.each do |col|
|
|
1638
|
+
# Visit destination columns directly; missing keys still append nil.
|
|
1639
|
+
col << row[col.header]
|
|
1578
1640
|
end
|
|
1579
1641
|
self
|
|
1580
1642
|
end
|
|
@@ -1789,6 +1851,20 @@ module FatTable
|
|
|
1789
1851
|
result
|
|
1790
1852
|
end
|
|
1791
1853
|
|
|
1854
|
+
# Keys are normalized once per row. Swap operands for descending columns,
|
|
1855
|
+
# retaining the nil/tolerant-value comparison rules and original tie order.
|
|
1856
|
+
def compare_prepared_sort_keys(key1, key2, directions)
|
|
1857
|
+
key1.each_index do |i|
|
|
1858
|
+
a = key1[i]
|
|
1859
|
+
b = key2[i]
|
|
1860
|
+
a, b = b, a if directions[i] == :reverse
|
|
1861
|
+
result = a.equal?(b) ? 0 : a <=> b
|
|
1862
|
+
result = compare_with_nils([a], [b]) if result.nil?
|
|
1863
|
+
return result unless result == 0
|
|
1864
|
+
end
|
|
1865
|
+
0
|
|
1866
|
+
end
|
|
1867
|
+
|
|
1792
1868
|
# The <=> operator cannot handle nils without some help. Treat a nil as
|
|
1793
1869
|
# smaller than any other value, but equal to other nils. The two keys are
|
|
1794
1870
|
# assumed to be arrays of values to be compared with <=>. Since
|
data/lib/fat_table/version.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
|
5
|
+
echo "Usage: $0 [ROWS] (default: 10000)"
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
rows=${1:-10000}
|
|
10
|
+
if [[ $# -gt 1 || ! $rows =~ ^[1-9][0-9]*$ ]]; then
|
|
11
|
+
echo "Usage: $0 [ROWS] — ROWS must be a positive integer" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
|
|
16
|
+
export BENCH_ROWS=$rows
|
|
17
|
+
exec bundle exec ruby -Ilib benchmark/column.rb --text
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
def read_results(path)
|
|
7
|
+
results = File.foreach(path).reject { |line| line.strip.empty? }.map { |line| JSON.parse(line) }
|
|
8
|
+
names = results.map { |result| result.fetch('name') }
|
|
9
|
+
raise ArgumentError, "#{path}: empty results or duplicate operation names" if names.empty? || names.uniq != names
|
|
10
|
+
|
|
11
|
+
results.to_h { |result| [result.fetch('name'), result] }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def median(values)
|
|
15
|
+
sorted = values.sort
|
|
16
|
+
middle = sorted.size / 2
|
|
17
|
+
sorted.size.odd? ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2.0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def measurements(result)
|
|
21
|
+
samples = result.fetch('samples')
|
|
22
|
+
raise ArgumentError, 'samples must not be empty' if samples.empty?
|
|
23
|
+
|
|
24
|
+
samples.each do |sample|
|
|
25
|
+
seconds = sample.fetch('seconds')
|
|
26
|
+
allocations = sample.fetch('allocations')
|
|
27
|
+
unless seconds.is_a?(Numeric) && seconds.positive? && allocations.is_a?(Numeric) && allocations >= 0
|
|
28
|
+
raise ArgumentError, 'samples must have positive times and nonnegative allocations'
|
|
29
|
+
end
|
|
30
|
+
raise ArgumentError, 'samples must have output digests' unless sample.fetch('digest').is_a?(String)
|
|
31
|
+
end
|
|
32
|
+
[median(samples.map { |sample| sample['seconds'] }), median(samples.map { |sample| sample['allocations'] })]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def compare_results(before_path, after_path)
|
|
36
|
+
before = read_results(before_path)
|
|
37
|
+
after = read_results(after_path)
|
|
38
|
+
raise ArgumentError, 'operation names differ between files' unless before.keys.sort == after.keys.sort
|
|
39
|
+
|
|
40
|
+
puts "\n#{File.basename(before_path)} → #{File.basename(after_path)}"
|
|
41
|
+
printf "%-22s %11s %11s %9s %14s %14s %10s %8s\n",
|
|
42
|
+
'Operation',
|
|
43
|
+
'Before ms',
|
|
44
|
+
'After ms',
|
|
45
|
+
'Speedup',
|
|
46
|
+
'Alloc before',
|
|
47
|
+
'Alloc after',
|
|
48
|
+
'Alloc drop',
|
|
49
|
+
'Output'
|
|
50
|
+
matched = true
|
|
51
|
+
before.each do |name, old|
|
|
52
|
+
current = after.fetch(name)
|
|
53
|
+
unless old.reject { |key, _| key == 'samples' } == current.reject { |key, _| key == 'samples' }
|
|
54
|
+
raise ArgumentError, "#{name}: workload metadata differs (including row count or Ruby version)"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
old_time, old_alloc = measurements(old)
|
|
58
|
+
new_time, new_alloc = measurements(current)
|
|
59
|
+
digests = (old['samples'] + current['samples']).map { |sample| sample['digest'] }.uniq
|
|
60
|
+
same_output = digests.size == 1
|
|
61
|
+
matched &&= same_output
|
|
62
|
+
allocation_drop = old_alloc.zero? ? 'n/a' : format('%.1f%%', 100 * (1 - new_alloc.to_f / old_alloc))
|
|
63
|
+
printf "%-22s %11.3f %11.3f %8.2fx %14s %14s %10s %8s\n",
|
|
64
|
+
name,
|
|
65
|
+
old_time * 1000,
|
|
66
|
+
new_time * 1000,
|
|
67
|
+
old_time / new_time,
|
|
68
|
+
old_alloc,
|
|
69
|
+
new_alloc,
|
|
70
|
+
allocation_drop,
|
|
71
|
+
same_output ? 'match' : 'DIFF'
|
|
72
|
+
end
|
|
73
|
+
matched
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
usage = "Usage: #{File.basename($PROGRAM_NAME)} [BEFORE.jsonl AFTER.jsonl]"
|
|
77
|
+
if ARGV == ['--help'] || ARGV == ['-h']
|
|
78
|
+
puts usage
|
|
79
|
+
puts 'With no arguments, compare all recorded baseline/optimized pairs in benchmark/.'
|
|
80
|
+
exit
|
|
81
|
+
end
|
|
82
|
+
abort usage unless ARGV.empty? || ARGV.size == 2
|
|
83
|
+
|
|
84
|
+
pairs =
|
|
85
|
+
if ARGV.empty?
|
|
86
|
+
directory = File.expand_path('../benchmark', __dir__)
|
|
87
|
+
[
|
|
88
|
+
['formatting-baseline-4000.jsonl', 'formatting-buffer-4000.jsonl'],
|
|
89
|
+
['joins-baseline-200.jsonl', 'joins-indexed-200.jsonl'],
|
|
90
|
+
['sort-baseline-4000.jsonl', 'sort-prepared-4000.jsonl'],
|
|
91
|
+
['insertion-baseline-1000.jsonl', 'insertion-direct-1000.jsonl'],
|
|
92
|
+
['column-baseline-10000.jsonl', 'column-fast-10000.jsonl'],
|
|
93
|
+
].map { |pair| pair.map { |file| File.join(directory, file) } }
|
|
94
|
+
else
|
|
95
|
+
[ARGV]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
begin
|
|
99
|
+
puts 'Recorded benchmark comparison (medians; no benchmarks are run).'
|
|
100
|
+
outcomes = pairs.map { |before, after| compare_results(before, after) }
|
|
101
|
+
puts "\nSpeedup = before / after. Negative allocation drop means more allocations."
|
|
102
|
+
exit(outcomes.all? ? 0 : 1)
|
|
103
|
+
rescue ArgumentError, KeyError, TypeError, JSON::ParserError, SystemCallError => e
|
|
104
|
+
abort "Comparison failed: #{e.message}"
|
|
105
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
|
5
|
+
echo "Usage: $0 [ROWS] (default: 4000)"
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
rows=${1:-4000}
|
|
10
|
+
if [[ $# -gt 1 || ! $rows =~ ^[1-9][0-9]*$ ]]; then
|
|
11
|
+
echo "Usage: $0 [ROWS] — ROWS must be a positive integer" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
|
|
16
|
+
export BENCH_ROWS=$rows
|
|
17
|
+
exec bundle exec ruby -Ilib benchmark/transform_and_render.rb --text
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
|
5
|
+
echo "Usage: $0 [ROWS] (default: 1000)"
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
rows=${1:-1000}
|
|
10
|
+
if [[ $# -gt 1 || ! $rows =~ ^[1-9][0-9]*$ ]]; then
|
|
11
|
+
echo "Usage: $0 [ROWS] — ROWS must be a positive integer" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
|
|
16
|
+
export BENCH_ROWS=$rows
|
|
17
|
+
exec bundle exec ruby -Ilib benchmark/insertion.rb --text
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
|
5
|
+
echo "Usage: $0 [ROWS] (default: 200)"
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
rows=${1:-200}
|
|
10
|
+
if [[ $# -gt 1 || ! $rows =~ ^[1-9][0-9]*$ ]]; then
|
|
11
|
+
echo "Usage: $0 [ROWS] — ROWS must be a positive integer" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
|
|
16
|
+
export BENCH_ROWS=$rows
|
|
17
|
+
exec bundle exec ruby -Ilib benchmark/joins.rb --text
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
|
5
|
+
echo "Usage: $0 [ROWS] (default: 4000)"
|
|
6
|
+
exit 0
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
rows=${1:-4000}
|
|
10
|
+
if [[ $# -gt 1 || ! $rows =~ ^[1-9][0-9]*$ ]]; then
|
|
11
|
+
echo "Usage: $0 [ROWS] — ROWS must be a positive integer" >&2
|
|
12
|
+
exit 1
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
|
|
16
|
+
export BENCH_ROWS=$rows
|
|
17
|
+
exec bundle exec ruby -Ilib benchmark/sort.rb --text
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fat_table
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-27 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: csv
|
|
@@ -133,6 +133,22 @@ files:
|
|
|
133
133
|
- README.rdoc
|
|
134
134
|
- Rakefile
|
|
135
135
|
- TODO.org
|
|
136
|
+
- benchmark/README.org
|
|
137
|
+
- benchmark/column-baseline-10000.jsonl
|
|
138
|
+
- benchmark/column-fast-10000.jsonl
|
|
139
|
+
- benchmark/column.rb
|
|
140
|
+
- benchmark/formatting-baseline-4000.jsonl
|
|
141
|
+
- benchmark/formatting-buffer-4000.jsonl
|
|
142
|
+
- benchmark/insertion-baseline-1000.jsonl
|
|
143
|
+
- benchmark/insertion-direct-1000.jsonl
|
|
144
|
+
- benchmark/insertion.rb
|
|
145
|
+
- benchmark/joins-baseline-200.jsonl
|
|
146
|
+
- benchmark/joins-indexed-200.jsonl
|
|
147
|
+
- benchmark/joins.rb
|
|
148
|
+
- benchmark/sort-baseline-4000.jsonl
|
|
149
|
+
- benchmark/sort-prepared-4000.jsonl
|
|
150
|
+
- benchmark/sort.rb
|
|
151
|
+
- benchmark/transform_and_render.rb
|
|
136
152
|
- bin/ft_console
|
|
137
153
|
- bin/setup
|
|
138
154
|
- data/xcolors.txt
|
|
@@ -159,6 +175,12 @@ files:
|
|
|
159
175
|
- lib/fat_table/table.rb
|
|
160
176
|
- lib/fat_table/version.rb
|
|
161
177
|
- md/README.md
|
|
178
|
+
- scripts/benchmark-column
|
|
179
|
+
- scripts/benchmark-compare
|
|
180
|
+
- scripts/benchmark-formatting
|
|
181
|
+
- scripts/benchmark-insertion
|
|
182
|
+
- scripts/benchmark-joins
|
|
183
|
+
- scripts/benchmark-sort
|
|
162
184
|
homepage: https://github.com/ddoherty03/fat_table
|
|
163
185
|
licenses: []
|
|
164
186
|
metadata:
|