Created
December 31, 2020 19:07
-
-
Save gwpl/7e6e3e210585040e7167f0e1e95236af to your computer and use it in GitHub Desktop.
playing with tracy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "profiling_test" | |
version = "0.1.0" | |
authors = ["root <root@localhost>"] | |
edition = "2018" | |
[dependencies] | |
profiling = "0.1" | |
tracy-client = { version = "0.10", optional = true } | |
#[profile.release] | |
#debug = true | |
[features] | |
profile-with-tracy = ["tracy-client", "profiling/profile-with-tracy"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: src/main.rs | |
use std::env; | |
//#[profiling::function] | |
fn tree_s(level: i32, s0: String) -> i64 { | |
profiling::scope!(format!("bin_tree={}", level).as_str()); | |
let mut s: String = s0.to_owned(); | |
s.push_str("-"); | |
if level <= 0 { | |
burn_time(1); | |
println!("{}*", s); | |
return 1; | |
} else { | |
println!("{}.", s); | |
return tree_s(level-1, s.to_owned()) + tree_s(level-2, s); | |
} | |
} | |
fn tree(level: i32) -> i64 { | |
return tree_s(level, "|".to_string()); | |
} | |
//#[profiling::function] | |
fn burn_time(millis: u128) { | |
let start_time = std::time::Instant::now(); | |
loop { | |
if (std::time::Instant::now() - start_time).as_millis() > millis { | |
break; | |
} | |
} | |
} | |
fn main() { | |
// Good to call this on any threads that are created to get clearer profiling results | |
profiling::register_thread!("BinTree"); | |
//let args: Vec<String> = env::args().collect(); | |
println!("Hello, world!"); | |
if let Some(arg1) = env::args().nth(1) { | |
println!("The first argument is {}", arg1); | |
let p: i32 = arg1.parse().expect("First argument is supposed to be small positive integer"); | |
let r = tree(p); | |
println!("bintree({}): {}", p, r); | |
} else { | |
println!("Please provide integer as first argument"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment