extern crate dotscope;
use criterion::{criterion_group, criterion_main, Criterion};
use dotscope::metadata::signatures::{
parse_field_signature, parse_local_var_signature, parse_method_signature,
parse_method_spec_signature, parse_property_signature, parse_type_spec_signature,
};
use std::hint::black_box;
fn bench_method_signature_void_no_params(c: &mut Criterion) {
let signature = [0x00, 0x00, 0x01];
c.bench_function("sig_method_void_no_params", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_primitives(c: &mut Criterion) {
let signature = [0x00, 0x03, 0x08, 0x08, 0x0E, 0x02];
c.bench_function("sig_method_primitives", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_instance(c: &mut Criterion) {
let signature = [0x20, 0x01, 0x01, 0x08];
c.bench_function("sig_method_instance", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_generic(c: &mut Criterion) {
let signature = [0x30, 0x01, 0x01, 0x1E, 0x00, 0x1E, 0x00];
c.bench_function("sig_method_generic", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_multi_generic(c: &mut Criterion) {
let signature = [0x30, 0x02, 0x01, 0x1E, 0x01, 0x1E, 0x00];
c.bench_function("sig_method_multi_generic", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_byref(c: &mut Criterion) {
let signature = [0x00, 0x02, 0x01, 0x10, 0x08, 0x10, 0x0E];
c.bench_function("sig_method_byref", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_array_return(c: &mut Criterion) {
let signature = [0x00, 0x00, 0x1D, 0x08];
c.bench_function("sig_method_array_return", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_signature_many_params(c: &mut Criterion) {
let signature = [
0x00, 0x08, 0x01, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
];
c.bench_function("sig_method_many_params", |b| {
b.iter(|| {
let sig = parse_method_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_field_signature_primitive(c: &mut Criterion) {
let signature = [0x06, 0x08];
c.bench_function("sig_field_primitive", |b| {
b.iter(|| {
let sig = parse_field_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_field_signature_string(c: &mut Criterion) {
let signature = [0x06, 0x0E];
c.bench_function("sig_field_string", |b| {
b.iter(|| {
let sig = parse_field_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_field_signature_array(c: &mut Criterion) {
let signature = [0x06, 0x1D, 0x08];
c.bench_function("sig_field_array", |b| {
b.iter(|| {
let sig = parse_field_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_field_signature_generic_param(c: &mut Criterion) {
let signature = [0x06, 0x13, 0x00];
c.bench_function("sig_field_generic_param", |b| {
b.iter(|| {
let sig = parse_field_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_field_signature_class(c: &mut Criterion) {
let signature = [0x06, 0x12, 0x49];
c.bench_function("sig_field_class", |b| {
b.iter(|| {
let sig = parse_field_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_property_signature_simple(c: &mut Criterion) {
let signature = [0x28, 0x00, 0x08];
c.bench_function("sig_property_simple", |b| {
b.iter(|| {
let sig = parse_property_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_property_signature_indexer(c: &mut Criterion) {
let signature = [0x28, 0x01, 0x0E, 0x08];
c.bench_function("sig_property_indexer", |b| {
b.iter(|| {
let sig = parse_property_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_property_signature_static(c: &mut Criterion) {
let signature = [0x08, 0x00, 0x08];
c.bench_function("sig_property_static", |b| {
b.iter(|| {
let sig = parse_property_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_local_var_signature_single(c: &mut Criterion) {
let signature = [0x07, 0x01, 0x08];
c.bench_function("sig_localvar_single", |b| {
b.iter(|| {
let sig = parse_local_var_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_local_var_signature_multiple(c: &mut Criterion) {
let signature = [0x07, 0x04, 0x08, 0x0E, 0x02, 0x1C];
c.bench_function("sig_localvar_multiple", |b| {
b.iter(|| {
let sig = parse_local_var_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_local_var_signature_byref(c: &mut Criterion) {
let signature = [0x07, 0x02, 0x10, 0x08, 0x10, 0x0E];
c.bench_function("sig_localvar_byref", |b| {
b.iter(|| {
let sig = parse_local_var_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_local_var_signature_pinned(c: &mut Criterion) {
let signature = [0x07, 0x01, 0x45, 0x0F, 0x08];
c.bench_function("sig_localvar_pinned", |b| {
b.iter(|| {
let sig = parse_local_var_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_local_var_signature_many(c: &mut Criterion) {
let signature = [
0x07, 0x0A, 0x08, 0x0E, 0x02, 0x1C, 0x08, 0x0E, 0x08, 0x08, 0x1C, 0x02, ];
c.bench_function("sig_localvar_many", |b| {
b.iter(|| {
let sig = parse_local_var_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_type_spec_generic_simple(c: &mut Criterion) {
let signature = [0x15, 0x12, 0x49, 0x01, 0x08];
c.bench_function("sig_typespec_generic_simple", |b| {
b.iter(|| {
let sig = parse_type_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_type_spec_generic_multi_arg(c: &mut Criterion) {
let signature = [0x15, 0x12, 0x49, 0x02, 0x0E, 0x08];
c.bench_function("sig_typespec_generic_multi_arg", |b| {
b.iter(|| {
let sig = parse_type_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_type_spec_array(c: &mut Criterion) {
let signature = [0x1D, 0x08];
c.bench_function("sig_typespec_array", |b| {
b.iter(|| {
let sig = parse_type_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_type_spec_pointer(c: &mut Criterion) {
let signature = [0x0F, 0x08];
c.bench_function("sig_typespec_pointer", |b| {
b.iter(|| {
let sig = parse_type_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_type_spec_generic_param(c: &mut Criterion) {
let signature = [0x13, 0x00];
c.bench_function("sig_typespec_generic_param", |b| {
b.iter(|| {
let sig = parse_type_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_spec_single(c: &mut Criterion) {
let signature = [0x0A, 0x01, 0x08];
c.bench_function("sig_methodspec_single", |b| {
b.iter(|| {
let sig = parse_method_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_spec_multiple(c: &mut Criterion) {
let signature = [0x0A, 0x03, 0x08, 0x0E, 0x02];
c.bench_function("sig_methodspec_multiple", |b| {
b.iter(|| {
let sig = parse_method_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
fn bench_method_spec_nested_generic(c: &mut Criterion) {
let signature = [0x0A, 0x01, 0x15, 0x12, 0x49, 0x01, 0x08];
c.bench_function("sig_methodspec_nested_generic", |b| {
b.iter(|| {
let sig = parse_method_spec_signature(black_box(&signature)).unwrap();
black_box(sig)
});
});
}
criterion_group!(
benches,
bench_method_signature_void_no_params,
bench_method_signature_primitives,
bench_method_signature_instance,
bench_method_signature_generic,
bench_method_signature_multi_generic,
bench_method_signature_byref,
bench_method_signature_array_return,
bench_method_signature_many_params,
bench_field_signature_primitive,
bench_field_signature_string,
bench_field_signature_array,
bench_field_signature_generic_param,
bench_field_signature_class,
bench_property_signature_simple,
bench_property_signature_indexer,
bench_property_signature_static,
bench_local_var_signature_single,
bench_local_var_signature_multiple,
bench_local_var_signature_byref,
bench_local_var_signature_pinned,
bench_local_var_signature_many,
bench_type_spec_generic_simple,
bench_type_spec_generic_multi_arg,
bench_type_spec_array,
bench_type_spec_pointer,
bench_type_spec_generic_param,
bench_method_spec_single,
bench_method_spec_multiple,
bench_method_spec_nested_generic,
);
criterion_main!(benches);