feat: add __performance
This commit is contained in:
@@ -62,6 +62,8 @@ Project or files:
|
||||
│ ├── pcap
|
||||
│ ├── tcp
|
||||
│ └── udp_laminar
|
||||
├── __performance
|
||||
│ └── print_perf
|
||||
├── __search
|
||||
│ ├── simsearch
|
||||
│ └── tantivy
|
||||
@@ -125,7 +127,7 @@ Project or files:
|
||||
├── vec.rs
|
||||
└── while.rs
|
||||
|
||||
97 directories, 26 files
|
||||
99 directories, 26 files
|
||||
|
||||
```
|
||||
|
||||
|
||||
14
__performance/print_perf/Cargo.lock
generated
Normal file
14
__performance/print_perf/Cargo.lock
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "print_perf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"print_perf 0.1.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "print_perf"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04378d9c598036cd5c61d71245b4e5e3e6455d1f2ab2120a7b9055dace8d8a47"
|
||||
10
__performance/print_perf/Cargo.toml
Normal file
10
__performance/print_perf/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "print_perf"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
print_perf = "0.1"
|
||||
34
__performance/print_perf/src/main.rs
Normal file
34
__performance/print_perf/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use print_perf::*;
|
||||
// or explicit print_perf::{perf, Perf};
|
||||
use std::time::Duration;
|
||||
use std::thread::sleep;
|
||||
|
||||
fn add(a: i32, b: i32) -> i32 {
|
||||
sleep(Duration::from_millis(100));
|
||||
a + b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("main_1()");
|
||||
main_1();
|
||||
println!("main_2()");
|
||||
main_2();
|
||||
}
|
||||
|
||||
fn main_1() {
|
||||
let add_p = perf!("add fn");
|
||||
let result = add(4, 4);
|
||||
add_p.end();
|
||||
// ^-- prints: 0.100140446 (add fn) @ [src/main.rs:9]
|
||||
assert_eq!(result, 8);
|
||||
}
|
||||
|
||||
|
||||
fn main_2() {
|
||||
let p = perf!("add fn");
|
||||
let _result = add(4, 4);
|
||||
p.split("add");
|
||||
let _div = _result / 2;
|
||||
p.split("div");
|
||||
p.end();
|
||||
}
|
||||
Reference in New Issue
Block a user