Files
ssw c303c315e5 rocr: rusto-rs 源码入库(上游 v0.2.5 基线 57609fc + 本地补丁)
- 源码 316 文件收编为 rusto-rs/ 文件夹,随本仓库管理
- 移除内部 .git(补丁已存档 docs/rusto-rs-metal-patch-20260912.patch,上游可随时 re-clone)
- target/ 与 docs/.yarn 缓存不入库;本地改动:ROCR_* 环境变量调优 + Metal 链接修复 + 预处理测试脚本
2026-09-12 17:30:04 +08:00

68 lines
2.4 KiB
Rust

use rusto::{DetectTextResult, ImageSource, InitializeConfig, OcrRunOptions, RustO};
use std::time::Instant;
fn main() {
println!("=== RustO Performance Test ===\n");
let config = InitializeConfig::ppv5(
"models/PPOCR_v5/det.mnn",
"models/PPOCR_v5/rec.mnn",
"models/PPOCR_v5/dict.txt"
);
println!("Initializing OCR engine...");
let init_start = Instant::now();
let mut ocr = RustO::initialize(config).expect("Failed to create OCR");
println!("Initialization took: {:?}\n", init_start.elapsed());
let test_images = vec![
("example1", "models/test_images/example1.png"),
];
for (name, path) in &test_images {
if !std::path::Path::new(path).exists() {
println!("⚠ Skipping {} - file not found: {}\n", name, path);
continue;
}
println!("Testing {} ({}):", name, path);
// Warmup run
println!(" Warmup run...");
let _ = ocr.detect_text(&ImageSource::Path(path.into()), &OcrRunOptions::default());
// Timed runs
let num_runs = 5;
let mut times = Vec::new();
for i in 1..=num_runs {
let start = Instant::now();
let results = ocr.detect_text(&ImageSource::Path(path.into()), &OcrRunOptions::default()).expect("OCR failed");
let elapsed = start.elapsed();
times.push(elapsed);
match results {
DetectTextResult::Structured(items) => {
println!(" Run {}: {:?} - {} text regions detected", i, elapsed, items.len());
if i == 1 && !items.is_empty() {
println!(" Sample result: {} (score: {:.3})", items[0].text, items[0].score);
}
}
DetectTextResult::Spatial(_) => unreachable!("default output is structured"),
}
}
// Calculate statistics
let total: std::time::Duration = times.iter().sum();
let avg = total / num_runs as u32;
let min = times.iter().min().unwrap();
let max = times.iter().max().unwrap();
println!("\n Statistics:");
println!(" Average: {:?}", avg);
println!(" Min: {:?}", min);
println!(" Max: {:?}", max);
println!(" Throughput: {:.2} images/sec\n", 1.0 / avg.as_secs_f64());
}
}