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 = 08+
while i < n9+
name = names[i % 5]10+
dept = depts[i % 4]11+
salary = 30000 + (i * 1337) % 7000012+
age = 22 + i % 4013+
lines.push(name + "," + dept + "," + salary.to_s + "," + age.to_s)14+
i = i + 115+
end16+
lines17+
end18+
19+
def process_lines(lines)20+
total_salary = 021+
high_earners = 022+
dept_counts = {}23+
i = 124+
while i < lines.length25+
fields = lines[i].split(",")26+
if fields.length >= 427+
dept = fields[1]28+
salary = fields[2].to_i29+
total_salary = total_salary + salary30+
if salary >= 8000031+
high_earners = high_earners + 132+
end33+
if dept_counts.has_key?(dept)34+
dept_counts[dept] = dept_counts[dept] + 135+
else36+
dept_counts[dept] = 137+
end38+
end39+
i = i + 140+
end41+
puts lines.length - 142+
puts total_salary43+
puts high_earners44+
dept_counts.each { |k, v|45+
puts k + ": " + v.to_s46+
}47+
end48+
49+
lines = generate_lines(5000)50+
process_lines(lines)51+
52+
# Benchmark: process 200 times53+
i = 054+
while i < 20055+
process_lines(lines)56+
i = i + 157+
end58+
puts "done"benchmark/template.rbaddedView file
Loading diff…