Commit afcf936e
afcf936e27b8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · +1 added · ~1 modified
Description
fix: File.open write block with while/if loops
compile_file_block_stmt now recursively handles WhileNode and IfNode inside File.open blocks, so f.puts works inside while loops.
Add io_wordcount benchmark (5.2x vs Ruby): line-by-line file reading with Hash word frequency counting.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- afcf936e27b8
- Parent
- da62c0e2c75c
benchmark/io_wordcount.rbaddedView file
1+
# Line-by-line file processing with File.open block2+
# Tests: File.open, each_line, string split, Hash3+
4+
# Write test data: word frequency file5+
words = ["the", "quick", "brown", "fox", "jumps", "over", "lazy", "dog"]6+
File.open("/tmp/spinel_io_wf.txt", "w") do |f|7+
i = 08+
while i < 50009+
w = words[i % 8]10+
f.puts(w + " " + (i % 100).to_s)11+
i = i + 112+
end13+
end14+
15+
# Process: count word frequencies16+
counts = {}17+
File.open("/tmp/spinel_io_wf.txt", "r") do |f|18+
f.each_line do |line|19+
parts = line.strip.split(" ")20+
if parts.length >= 121+
word = parts[0]22+
if counts.has_key?(word)23+
counts[word] = counts[word] + 124+
else25+
counts[word] = 126+
end27+
end28+
end29+
end30+
31+
# Print sorted results32+
counts.each do |k, v|33+
puts k + ": " + v.to_s34+
end35+
36+
# Process 20 times for benchmark37+
i = 038+
while i < 2039+
c = {}40+
File.open("/tmp/spinel_io_wf.txt", "r") do |f|41+
f.each_line do |line|42+
parts = line.strip.split(" ")43+
if parts.length >= 144+
w = parts[0]45+
if c.has_key?(w)46+
c[w] = c[w] + 147+
else48+
c[w] = 149+
end50+
end51+
end52+
end53+
i = i + 154+
end55+
56+
File.delete("/tmp/spinel_io_wf.txt")57+
puts "done"spinel_codegen.rbmodifiedView file
Loading diff…