feat: add __performance

This commit is contained in:
2020-11-07 12:23:25 +08:00
parent e6917877cc
commit 79efa59a34
4 changed files with 61 additions and 1 deletions

View File

@@ -62,6 +62,8 @@ Project or files:
│   ├── pcap │   ├── pcap
│   ├── tcp │   ├── tcp
│   └── udp_laminar │   └── udp_laminar
├── __performance
│   └── print_perf
├── __search ├── __search
│   ├── simsearch │   ├── simsearch
│   └── tantivy │   └── tantivy
@@ -125,7 +127,7 @@ Project or files:
├── vec.rs ├── vec.rs
└── while.rs └── while.rs
97 directories, 26 files 99 directories, 26 files
``` ```

14
__performance/print_perf/Cargo.lock generated Normal file
View 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"

View 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"

View 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();
}