|
| 1 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 2 | +use techscript_ir::builder::IRBuilder; |
| 3 | +use techscript_ir::types::IRType; |
| 4 | + |
| 5 | +fn criterion_benchmark(c: &mut Criterion) { |
| 6 | + c.bench_function("seal_function 10000 blocks", |b| { |
| 7 | + b.iter(|| { |
| 8 | + let mut builder = IRBuilder::new(); |
| 9 | + builder.start_function("bench_func".to_string(), IRType::Void); |
| 10 | + |
| 11 | + let num_blocks = 10000; |
| 12 | + let mut blocks = vec![]; |
| 13 | + for i in 0..num_blocks { |
| 14 | + let block_id = builder.new_block(format!("block_{}", i)); |
| 15 | + blocks.push(block_id); |
| 16 | + } |
| 17 | + |
| 18 | + for i in 0..(num_blocks - 1) { |
| 19 | + builder.enter_block(blocks[i], format!("block_{}", i)); |
| 20 | + builder.emit_terminator( |
| 21 | + techscript_ir::instruction::TerminatorKind::Jump(blocks[i + 1]), |
| 22 | + techscript_common::Span { start: 0, end: 0 }, |
| 23 | + ); |
| 24 | + } |
| 25 | + |
| 26 | + builder.enter_block(blocks[num_blocks - 1], format!("block_{}", num_blocks - 1)); |
| 27 | + builder.emit_terminator( |
| 28 | + techscript_ir::instruction::TerminatorKind::Return(None), |
| 29 | + techscript_common::Span { start: 0, end: 0 }, |
| 30 | + ); |
| 31 | + |
| 32 | + builder.seal_function(); |
| 33 | + }); |
| 34 | + }); |
| 35 | +} |
| 36 | + |
| 37 | +criterion_group!(benches, criterion_benchmark); |
| 38 | +criterion_main!(benches); |
0 commit comments