Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node_modules/

# Editor:
.vscode/**/*
**/*.code-workspace
# ...except shared workspace settings that should be checked in:
!.vscode/settings.json
!.vscode/extensions.json
51 changes: 31 additions & 20 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
//! Benchmark to measure (and then optimize) the implementation
//! of the histogram generation for the Mandelbrot set.
//! This in practice will exercise both the histogram and mandelbrot
//! core evaluation.
//! Benchmark for the fractal rendering pipeline. Runs `RenderingPipeline::render`
//! end-to-end (compute_raw_field → populate_histograms → CDF rebuild →
//! refresh_cache → colorize_collapse_unified) at the user's full sampling
//! level on a representative Mandelbrot example.
use criterion::{Criterion, black_box, criterion_group, criterion_main};
use fractal_renderer::fractals::{
mandelbrot::MandelbrotParams,
quadratic_map::{QuadraticMapParams, create_empty_histogram},
utilities::populate_histogram,
use egui::{Color32, ColorImage};
use fractal_renderer::{
core::{
image_utils::{Renderable, field_upsample_factor},
render_pipeline::RenderingPipeline,
},
fractals::mandelbrot::MandelbrotParams,
};

pub fn run_quadratic_map_histogram_benchmark(c: &mut Criterion, path: &str) {
fn run_pipeline_render_benchmark(c: &mut Criterion, path: &str) {
let mandelbrot_params: MandelbrotParams =
serde_json::from_str(&std::fs::read_to_string(path).expect("Unable to read param file"))
.unwrap();

let histogram = create_empty_histogram(&mandelbrot_params);
let renderer = mandelbrot_params;
let resolution = renderer.image_specification().resolution;
let n_max_plus_1 = field_upsample_factor(renderer.render_options().sampling_level);
let bin_count = renderer.histogram_bin_count();
let hist_max = renderer.histogram_max_value();
let lut_count = renderer.lookup_table_count();
let sampling_level = renderer.render_options().sampling_level;

let mut pipeline =
RenderingPipeline::new(renderer, n_max_plus_1, bin_count, hist_max, lut_count);
let mut color_image = ColorImage::filled(
[resolution[0] as usize, resolution[1] as usize],
Color32::BLACK,
);

c.bench_function(path, |b| {
b.iter(|| {
histogram.reset();
populate_histogram(
&|point: &[f64; 2]| mandelbrot_params.normalized_log_escape_count(point),
mandelbrot_params.image_specification(),
mandelbrot_params.color_map().histogram_sample_count as u32,
histogram.clone(),
);
black_box(&histogram);
pipeline.render(&mut color_image, sampling_level);
black_box(&color_image);
});
});
}

fn benchmark(c: &mut Criterion) {
run_quadratic_map_histogram_benchmark(c, "benches/mandelbrot_ice_fracture.json");
run_quadratic_map_histogram_benchmark(c, "benches/mandelbrot_default.json");
run_pipeline_render_benchmark(c, "benches/mandelbrot_ice_fracture.json");
run_pipeline_render_benchmark(c, "benches/mandelbrot_default.json");
}

criterion_group!(benches, benchmark);
Expand Down
44 changes: 22 additions & 22 deletions benches/mandelbrot_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@
},
"color_map": {
"color": {
"background": [0, 0, 0],
"color_map": [
{
"query": 0.0,
"rgb_raw": [50, 0, 100]
},
{
"query": 0.92,
"rgb_raw": [20, 0, 220]
},
{
"query": 0.97,
"rgb_raw": [0, 50, 230]
},
{
"query": 1.0,
"rgb_raw": [230, 245, 255]
}
"background_color": [0, 0, 0],
"color_maps": [
[
{
"query": 0.0,
"rgb_raw": [50, 0, 100]
},
{
"query": 0.92,
"rgb_raw": [20, 0, 220]
},
{
"query": 0.97,
"rgb_raw": [0, 50, 230]
},
{
"query": 1.0,
"rgb_raw": [230, 245, 255]
}
]
]
},
"lookup_table_count": 2048,
"histogram_bin_count": 32,
"histogram_sample_count": 40000
"histogram_bin_count": 32
},
"render_options": {
"downsample_stride": 1,
"subpixel_antialiasing": 0
"sampling_level": 0
}
}
52 changes: 26 additions & 26 deletions benches/mandelbrot_ice_fracture.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@
},
"color_map": {
"color": {
"background": [0, 0, 0],
"color_map": [
{
"query": 0.0,
"rgb_raw": [0, 0, 250]
},
{
"query": 0.9,
"rgb_raw": [40, 0, 80]
},
{
"query": 0.94,
"rgb_raw": [255, 125, 0]
},
{
"query": 0.99,
"rgb_raw": [10, 0, 20]
},
{
"query": 1.0,
"rgb_raw": [255, 150, 150]
}
"background_color": [0, 0, 0],
"color_maps": [
[
{
"query": 0.0,
"rgb_raw": [0, 0, 250]
},
{
"query": 0.9,
"rgb_raw": [40, 0, 80]
},
{
"query": 0.94,
"rgb_raw": [255, 125, 0]
},
{
"query": 0.99,
"rgb_raw": [10, 0, 20]
},
{
"query": 1.0,
"rgb_raw": [255, 150, 150]
}
]
]
},
"lookup_table_count": 2048,
"histogram_bin_count": 32,
"histogram_sample_count": 20000
"histogram_bin_count": 32
},
"render_options": {
"downsample_stride": 1,
"subpixel_antialiasing": 2
"sampling_level": 2
}
}
Loading
Loading