60 lines
2.0 KiB
Rust
60 lines
2.0 KiB
Rust
|
|
|
|
use std::hint::black_box;
|
|
use std::time::{Duration, Instant};
|
|
|
|
use eonacat_xsbox_gpu::formats::{texture, xma};
|
|
|
|
fn measure(name: &str, iterations: u64, mut operation: impl FnMut()) {
|
|
for _ in 0..(iterations / 20).max(1) {
|
|
operation();
|
|
}
|
|
let start = Instant::now();
|
|
for _ in 0..iterations {
|
|
operation();
|
|
}
|
|
let elapsed = start.elapsed();
|
|
let ns_per_op = elapsed.as_nanos() as f64 / iterations as f64;
|
|
println!("{name:32} {iterations:>12} iterations {ns_per_op:>10.2} ns/op ({})", format_duration(elapsed));
|
|
}
|
|
|
|
fn format_duration(duration: Duration) -> String {
|
|
if duration.as_secs() > 0 {
|
|
format!("{:.3}s", duration.as_secs_f64())
|
|
} else if duration.as_millis() > 0 {
|
|
format!("{:.3}ms", duration.as_secs_f64() * 1_000.0)
|
|
} else {
|
|
format!("{:.3}us", duration.as_secs_f64() * 1_000_000.0)
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
println!("EonaCat.XSBOX CPU microbenchmarks (release profile)");
|
|
println!("====================================================");
|
|
|
|
let formats = [1_u32, 2, 10, 19, 28, 44, 49, 60, 70, 73, 87, 94, 98, 116, 190, 999];
|
|
let mut format_index = 0usize;
|
|
measure("DXGI format lookup", 10_000_000, || {
|
|
black_box(texture::format(black_box(formats[format_index])));
|
|
format_index = (format_index + 1) % formats.len();
|
|
});
|
|
|
|
let layouts = [0_u32, 1, 2, 3, 0x101, 0x105, 0x109, 0x119];
|
|
let mut layout_index = 0usize;
|
|
measure("texture swizzle selection", 10_000_000, || {
|
|
black_box(texture::layout_swizzle(
|
|
black_box(texture::Dimension::Tex2d),
|
|
black_box(layouts[layout_index]),
|
|
black_box(0),
|
|
));
|
|
layout_index = (layout_index + 1) % layouts.len();
|
|
});
|
|
|
|
let packet_data = vec![0x5a_u8; xma::PACKET_BYTES * 8];
|
|
let mut packet_index = 0usize;
|
|
measure("XMA packet header parse", 10_000_000, || {
|
|
black_box(xma::packet(black_box(&packet_data), black_box(packet_index)));
|
|
packet_index = (packet_index + 1) % 8;
|
|
});
|
|
}
|