Commit eff714bd
eff714bd1040Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 3 files · +2 added · ~1 modified
Description
feat: add fasta benchmark (6.1x vs Ruby)
Fix float_array literal compilation in compile_array_literal and add fasta DNA sequence generation benchmark. Rewrites global variable usage to pass mutable state array as parameter.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- eff714bd1040
- Parent
- 15e86b2a6b2b
benchmark/bm_fasta.rbaddedView file
1+
# The Computer Language Benchmarks Game - Fasta2+
# Generate random DNA sequences3+
4+
IM = 1399685+
IA = 38776+
IC = 295737+
8+
# Mutable state via array cell (no global variables)9+
def gen_random(max, state)10+
state[0] = (state[0] * IA + IC) % IM11+
max * state[0] / IM12+
end13+
14+
def make_repeat_fasta(id, desc, src, n)15+
puts ">" + id + " " + desc16+
k = 017+
i = 018+
while i < n19+
len = 6020+
if n - i < 6021+
len = n - i22+
end23+
line = ""24+
j = 025+
while j < len26+
line = line + src[k % src.length]27+
k = k + 128+
j = j + 129+
end30+
puts line31+
i = i + len32+
end33+
end34+
35+
def make_random_fasta(id, desc, table_chars, table_probs, n, state)36+
puts ">" + id + " " + desc37+
# Build cumulative probabilities38+
cp = Array.new(table_probs.length, 0.0)39+
sum = 0.040+
k = 041+
while k < table_probs.length42+
sum = sum + table_probs[k]43+
cp[k] = sum44+
k = k + 145+
end46+
i = 047+
while i < n48+
len = 6049+
if n - i < 6050+
len = n - i51+
end52+
line = ""53+
j = 054+
while j < len55+
r = gen_random(1.0, state)56+
# Linear search57+
c = 058+
while c < cp.length - 159+
if r < cp[c]60+
break61+
end62+
c = c + 163+
end64+
line = line + table_chars[c]65+
j = j + 166+
end67+
puts line68+
i = i + len69+
end70+
end71+
72+
ALU = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAAAA"73+
74+
n = Integer(ARGV[0] || 1000)75+
state = [42]76+
77+
make_repeat_fasta("ONE", "Homo sapiens alu", ALU, n * 2)78+
79+
iub_chars = ["a", "c", "g", "t", "B", "D", "H", "K", "M", "N", "R", "S", "V", "W", "Y"]80+
iub_probs = [0.27, 0.12, 0.12, 0.27, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02]81+
82+
make_random_fasta("TWO", "IUB ambiguity codes", iub_chars, iub_probs, n * 3, state)83+
84+
homo_chars = ["a", "c", "g", "t"]85+
homo_probs = [0.3029549426680, 0.1979883004921, 0.1975473066391, 0.3015094502008]86+
87+
make_random_fasta("THREE", "Homo sapiens frequency", homo_chars, homo_probs, n * 5, state)spinel_codegen.rbmodifiedView file
Loading diff…
test/bm_fasta.rbaddedView file
Loading diff…