Browse Source

Add mandelbrot benchmark

master
Stephen 2 weeks ago
parent
commit
4c0f57d23d
1 changed files with 53 additions and 1 deletions
  1. +53
    -1
      benches/benchmark.rs

+ 53
- 1
benches/benchmark.rs View File

@ -51,5 +51,57 @@ end function
});
}
criterion_group!(benches, recursive_benchmark);
fn mandelbrot_benchmark(c: &mut Criterion) {
let test_io = TestIO::new("");
let mut xb = XBasic::new(test_io);
c.bench_function("mandelbrot 120x80", |b| {
b.iter(|| {
xb.run(
"
WIDTH = 120
HEIGHT = 80
MIN_X = -2
MAX_X = 1
MIN_Y = -1
MAX_Y = 1
function converges(Creal, Cimg, numIter)
i = 0
zr = 0
zrtmp = 0
zi = 0
while (zr * zr + zi * zi < 4)
i = i + 1
zrtemp = zr * zr + Creal - zi * zi
zi = 2 * zi * zr + Cimg
zr = zrtemp
if i > numIter then
return 0
end if
wend
return i
end function
function convertRange(ogStart, ogEnd, newStart, newEnd, value)
scale = (newEnd - newStart) / (ogEnd - ogStart)
return (newStart + ((value - ogStart) * scale))
end function
a = 20
for x = 0 to WIDTH
for y = 0 to HEIGHT
cr = convertRange(0, HEIGHT, MIN_Y, MAX_Y, y)
ci = convertRange(0, WIDTH, MIN_X, MAX_X, x)
c = converges(ci, cr, 85)
c = c * 30
if c > 0 then
c = c + 30
end if
a = 25
next y
next x
",
)
})
});
}
criterion_group!(benches, recursive_benchmark, mandelbrot_benchmark);
criterion_main!(benches);

Loading…
Cancel
Save