2024-08-13 22:45:42 -07:00
|
|
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
2024-11-20 15:19:25 +13:00
|
|
|
use kcl_lib::{test_server, UnitLength::Mm};
|
2024-08-13 22:45:42 -07:00
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
|
|
|
|
pub fn bench_execute(c: &mut Criterion) {
|
|
|
|
for (name, code) in [
|
|
|
|
("big_kitt", KITT_PROGRAM),
|
|
|
|
("cube", CUBE_PROGRAM),
|
2024-08-15 10:32:55 -07:00
|
|
|
("server_rack_lite", SERVER_RACK_LITE_PROGRAM),
|
2024-08-13 22:45:42 -07:00
|
|
|
("server_rack_heavy", SERVER_RACK_HEAVY_PROGRAM),
|
2024-10-29 21:40:31 -04:00
|
|
|
("lsystem", LSYSTEM_PROGRAM),
|
2024-08-13 22:45:42 -07:00
|
|
|
] {
|
|
|
|
let mut group = c.benchmark_group("executor");
|
|
|
|
// Configure Criterion.rs to detect smaller differences and increase sample size to improve
|
|
|
|
// precision and counteract the resulting noise.
|
|
|
|
group.sample_size(10);
|
Batch extrudes (#3764)
Adds a new KCL executor benchmark which builds a `10` wide by `n` tall lego, with varying `n`. The benchmark runs a n = 1, 2, 3 etc build, so we can get an idea of how the speed changes with size.
This change improves execution speed by 25-36% depending on how many bumps there are. Tested by:
* Rust unit tests
* Open up modeling app, sketch a square, use the command palette to extrude it
* Open up the Bambu printer "poop chute" model, it all extrudes and works fine
Also fixes a bug: extrude, loft, revolve all trigger a GetExtrusionFaceInfo command. Due to a bug, the GetExtrusionFaceInfo command reused the Command ID from the previous extrude/loft/revolve. Fixed that.
2024-09-06 16:55:24 -05:00
|
|
|
group.bench_with_input(BenchmarkId::new("execute", name), &code, |b, &s| {
|
2024-08-13 22:45:42 -07:00
|
|
|
let rt = Runtime::new().unwrap();
|
|
|
|
// Spawn a future onto the runtime
|
|
|
|
b.iter(|| {
|
2024-12-07 07:16:04 +13:00
|
|
|
rt.block_on(test_server::execute_and_snapshot(s, Mm, None)).unwrap();
|
2024-08-13 22:45:42 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
group.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Batch extrudes (#3764)
Adds a new KCL executor benchmark which builds a `10` wide by `n` tall lego, with varying `n`. The benchmark runs a n = 1, 2, 3 etc build, so we can get an idea of how the speed changes with size.
This change improves execution speed by 25-36% depending on how many bumps there are. Tested by:
* Rust unit tests
* Open up modeling app, sketch a square, use the command palette to extrude it
* Open up the Bambu printer "poop chute" model, it all extrudes and works fine
Also fixes a bug: extrude, loft, revolve all trigger a GetExtrusionFaceInfo command. Due to a bug, the GetExtrusionFaceInfo command reused the Command ID from the previous extrude/loft/revolve. Fixed that.
2024-09-06 16:55:24 -05:00
|
|
|
pub fn bench_lego(c: &mut Criterion) {
|
|
|
|
let mut group = c.benchmark_group("executor_lego_pattern");
|
|
|
|
// Configure Criterion.rs to detect smaller differences and increase sample size to improve
|
|
|
|
// precision and counteract the resulting noise.
|
|
|
|
group.sample_size(10);
|
|
|
|
// Create lego bricks with N x 10 bumps, where N is each element of `sizes`.
|
|
|
|
let sizes = vec![1, 2, 4];
|
|
|
|
for size in sizes {
|
|
|
|
group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| {
|
|
|
|
let rt = Runtime::new().unwrap();
|
|
|
|
let code = LEGO_PROGRAM.replace("{{N}}", &size.to_string());
|
|
|
|
// Spawn a future onto the runtime
|
|
|
|
b.iter(|| {
|
2024-12-07 07:16:04 +13:00
|
|
|
rt.block_on(test_server::execute_and_snapshot(&code, Mm, None)).unwrap();
|
Batch extrudes (#3764)
Adds a new KCL executor benchmark which builds a `10` wide by `n` tall lego, with varying `n`. The benchmark runs a n = 1, 2, 3 etc build, so we can get an idea of how the speed changes with size.
This change improves execution speed by 25-36% depending on how many bumps there are. Tested by:
* Rust unit tests
* Open up modeling app, sketch a square, use the command palette to extrude it
* Open up the Bambu printer "poop chute" model, it all extrudes and works fine
Also fixes a bug: extrude, loft, revolve all trigger a GetExtrusionFaceInfo command. Due to a bug, the GetExtrusionFaceInfo command reused the Command ID from the previous extrude/loft/revolve. Fixed that.
2024-09-06 16:55:24 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
group.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, bench_lego, bench_execute);
|
2024-08-13 22:45:42 -07:00
|
|
|
criterion_main!(benches);
|
|
|
|
|
2025-03-01 13:59:01 -08:00
|
|
|
const KITT_PROGRAM: &str = include_str!("../e2e/executor/inputs/kittycad_svg.kcl");
|
|
|
|
const CUBE_PROGRAM: &str = include_str!("../e2e/executor/inputs/cube.kcl");
|
|
|
|
const SERVER_RACK_HEAVY_PROGRAM: &str = include_str!("../e2e/executor/inputs/server-rack-heavy.kcl");
|
|
|
|
const SERVER_RACK_LITE_PROGRAM: &str = include_str!("../e2e/executor/inputs/server-rack-lite.kcl");
|
|
|
|
const LEGO_PROGRAM: &str = include_str!("../e2e/executor/inputs/slow_lego.kcl.tmpl");
|
|
|
|
const LSYSTEM_PROGRAM: &str = include_str!("../e2e/executor/inputs/lsystem.kcl");
|