diff --git a/benchmark/bm_mandel_term.rb b/benchmark/bm_mandel_term.rb new file mode 100644 index 000000000..460c2a6b9 --- /dev/null +++ b/benchmark/bm_mandel_term.rb @@ -0,0 +1,34 @@ +def mandelbrot(c_r, c_i) + limit=95 + iterations=0 + cr = (c_r * 100).to_i + ci = (c_i * 100).to_i + zr = zi = 0 + # Avoid sqrt by squaring the threshold: sqrt(x) < 1000 => x < 1000000 + while iterations= 1000000 + zr, zi = (zr2-zi2)/100+cr, (zr*zi*2)/100+ci + iterations+=1 + end + return iterations +end + +def mandel_calc(min_r, min_i, max_r, max_i, res) + cur_i = min_i + while cur_i > max_i + putc "|" + cur_r = min_r + while cur_r < max_r + ch = 127 - mandelbrot(cur_r, cur_i) + putc ch # Use putc with integer - no string allocation! + cur_r += res + end + putc "|" + putc "\n" + cur_i -= res + end +end + +mandel_calc(-2, 1, 1, -1, 0.04)