Commit af93e525

af93e525073bMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · +2 added

Description

feat: add practical benchmarks — JSON parser, CSV processor, template engine

Three new real-world benchmarks testing string processing, Hash operations, class methods, and recursive descent parsing:

  • json_parse: 4.5x vs Ruby (10K parses of nested JSON)
  • csv_process: 3.5x vs Ruby (200 passes over 5K-row CSV)
  • template: 2.6x vs Ruby (50K template renders with {{var}} substitution)

Also found and fixed: nullable object local variables (root = nil then root = Obj.new) still need type inference improvement for RB-tree etc.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
af93e525073b
Parent
e8a733bea6a2

benchmark/csv_process.rbaddedView file

1+# CSV processor - process only (no massive string concat in generate)
2+
3+def generate_lines(n)
4+ depts = ["eng", "sales", "hr", "ops"]
5+ names = ["alice", "bob", "carol", "dave", "eve"]
6+ lines = ["name,dept,salary,age"]
7+ i = 0
8+ while i < n
9+ name = names[i % 5]
10+ dept = depts[i % 4]
11+ salary = 30000 + (i * 1337) % 70000
12+ age = 22 + i % 40
13+ lines.push(name + "," + dept + "," + salary.to_s + "," + age.to_s)
14+ i = i + 1
15+ end
16+ lines
17+end
18+
19+def process_lines(lines)
20+ total_salary = 0
21+ high_earners = 0
22+ dept_counts = {}
23+ i = 1
24+ while i < lines.length
25+ fields = lines[i].split(",")
26+ if fields.length >= 4
27+ dept = fields[1]
28+ salary = fields[2].to_i
29+ total_salary = total_salary + salary
30+ if salary >= 80000
31+ high_earners = high_earners + 1
32+ end
33+ if dept_counts.has_key?(dept)
34+ dept_counts[dept] = dept_counts[dept] + 1
35+ else
36+ dept_counts[dept] = 1
37+ end
38+ end
39+ i = i + 1
40+ end
41+ puts lines.length - 1
42+ puts total_salary
43+ puts high_earners
44+ dept_counts.each { |k, v|
45+ puts k + ": " + v.to_s
46+ }
47+end
48+
49+lines = generate_lines(5000)
50+process_lines(lines)
51+
52+# Benchmark: process 200 times
53+i = 0
54+while i < 200
55+ process_lines(lines)
56+ i = i + 1
57+end
58+puts "done"