-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
907dc54
commit 038245e
Showing
6 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::fs::File; | ||
use std::io::{BufRead, BufReader, Lines, Result}; | ||
use std::path::Path; | ||
use std::process::exit; | ||
|
||
/* | ||
//// Info: | ||
// Finds and sums the time logs in this format: | ||
// ---c413: 0.134ms | ||
/// Usage: | ||
cargo r --example file_sum_time_logs ./files/time_log.txt 4121 | ||
str: 4121 | ||
count: 7 times | ||
sum: 0.94 ms | ||
*/ | ||
|
||
fn read_lines<P>(filename: P) -> Result<Lines<BufReader<File>>> | ||
where P: AsRef<Path>, { | ||
let file = File::open(filename)?; | ||
Ok(BufReader::new(file).lines()) | ||
} | ||
|
||
fn main() { | ||
println!( | ||
"Usage: cargo r --example file_sum_time_logs ./files/time_log.txt 4121" | ||
); | ||
let args: Vec<String> = std::env::args().collect(); | ||
let file = &args[1]; | ||
let find_str = &args[2]; | ||
let mut sum = 0.0; | ||
let mut count = 0; | ||
|
||
match read_lines(file) { | ||
Ok(lines) => { | ||
for line in lines.flatten() { | ||
if !line.contains(find_str) { continue; } | ||
let v: Vec<&str> = line.split(':').collect(); | ||
let num_str = v[1].trim().trim_end_matches("ms"); | ||
sum += num_str.parse::<f64>().unwrap_or_else( | ||
|_| { | ||
panic!("line: {}, num_str: {}", line, num_str) | ||
} | ||
); | ||
count += 1; | ||
} | ||
}, | ||
Err(e) => { println!("err: {}", e); exit(-1) }, | ||
} | ||
println!("str: {}", find_str); | ||
println!("count: {} times", count); | ||
println!("sum: {:.2} ms", sum); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// Run: | ||
// cargo r --example hello | ||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
println!("Hello from an example!"); | ||
println!("args: {:?}", args); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
---dataLayer: { | ||
id: '', | ||
name: '', | ||
startDate: '2021-01-01', | ||
endDate: '2029-12-01', | ||
base: true, | ||
readOnly: false | ||
} | ||
---c3: 5.922ms | ||
---nodes.size: 148 | ||
---c4121: 0.100ms | ||
---exit calculatePositions | ||
---c4121: 134ms | ||
---c4121: 0.40ms |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// see examples/file_sum_time_logs.rs |
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
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