rust - Rust 标准基准测试模块`未解决的导入`crate::some_module`
问题描述
我有一个包含许多内部模块来组织功能的二进制项目。
我正在尝试让Criterion为基准工作。
错误:
error[E0432]: unresolved import `crate::some_module`
--> benches/benchmarks.rs:3:5
|
3 | use crate::some_module;
| ^^^^^^^^^^^^^^^^^^ no `some_module` in the root
error: aborting due to previous error
最小示例.zip
:https ://drive.google.com/file/d/1TASKI9_ODJniamHp3RBRscoflabPT-kP/view?usp=sharing
我当前的最小示例如下所示:
.
├── Cargo.lock
├── Cargo.toml
├── src/
│ ├── main.rs
│ └── some_module/
│ ├── mod.rs
│ └── some_module_file.rs
└── benches/
└── benchmarks.rs
Cargo.toml
:
[package]
name = "criterion-bin-test"
version = "0.1.0"
authors = ["Jonathan <jonthanwoollettlight@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[dev-dependencies]
criterion = "0.3"
[[bench]]
name = "benchmarks"
harness = false
main.rs
:
mod some_module;
fn main() {
println!("Hello, world!");
println!("{}",some_module::some_mod_file::two());
}
mod.rs
:
pub mod some_mod_file;
some_module_file
:
pub fn two() -> i32 {
2
}
benchmarks.rs
:
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use crate::some_module;
fn fibonacci(n: u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
错误出现在 上use crate::some_module
,我无法弄清楚如何将 Criterion 基准测试应用到内部模块。非常感谢这里的任何帮助。
我当前项目中的测试按以下方式处理:
.
├── Cargo.lock
├── Cargo.toml
├── src/
| ├── main.rs
. ├── tests.rs
. some_module/
├── mod.rs
├── tests.rs
.
这允许use crate::some_module
.
解决方案
推荐阅读
- javafx - Javafx - 伪类中的伪类
- python - rasa_core 包中的 tensorflow 安装错误
- c# - 扩展方法中的“where T:class”VS常规类
- javascript - 在不同的浏览器中同时显示相同的内容
- javascript - 在矩形移相器 io 中添加图像
- apache - mod_evasive 不适用于 Apache 2.4.6
- c# - 错误 CS1501:方法“排序”没有重载采用“0”参数
- javascript - 使用 RegExp 构造函数导致错误输出
- android - Facebook Graph API 签入事件
- google-chrome-extension - 有什么方法可以链接到 chrome webstore 用户?