Rename --debug to --verbose and -v

This commit is contained in:
Kasper 2021-04-21 21:10:06 +02:00
parent 6585366b0d
commit ca273773ef
4 changed files with 16 additions and 16 deletions

8
Cargo.lock generated
View File

@ -35,9 +35,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.88"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "ord_subset"
@ -53,6 +53,6 @@ checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]]
name = "serde"
version = "1.0.124"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f"
checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"

View File

@ -89,7 +89,7 @@ cpc uses 128-bit Decimal Floating Point (d128) numbers instead of Binary Coded D
## Performance
It's pretty fast and scales well. In my case, it usually runs in under 0.1ms. The biggest performance hit is functions like `log()`. `log(12345)` evaluates in 0.12ms, and `log(e)` in 0.25ms.
To see how fast it is, you can pass the `--debug` flag in CLI, or the `debug` argument to `eval()`.
To see how fast it is, you can pass the `--verbose` flag in CLI, or the `verbose` argument to `eval()`.
## Dev Instructions
@ -101,9 +101,9 @@ Run cpc with a CLI argument as input:
cargo run -- '100ms to s'
```
Run with debugging, which shows some extra logs:
Run in verbose mode, which shows some extra logs:
```
cargo run -- '100ms to s' --debug
cargo run -- '100ms to s' --verbose
```
Run tests:

View File

@ -211,27 +211,27 @@ pub type TokenVector = Vec<Token>;
/// }
/// }
/// ```
pub fn eval(input: &str, allow_trailing_operators: bool, default_degree: Unit, debug: bool) -> Result<Number, String> {
pub fn eval(input: &str, allow_trailing_operators: bool, default_degree: Unit, verbose: bool) -> Result<Number, String> {
let lex_start = Instant::now();
match lexer::lex(input, allow_trailing_operators, default_degree) {
Ok(tokens) => {
let lex_time = Instant::now().duration_since(lex_start).as_nanos() as f32;
if debug == true { println!("Lexed TokenVector: {:?}", tokens); }
if verbose == true { println!("Lexed TokenVector: {:?}", tokens); }
let parse_start = Instant::now();
match parser::parse(&tokens) {
Ok(ast) => {
let parse_time = Instant::now().duration_since(parse_start).as_nanos() as f32;
if debug == true { println!("Parsed AstNode: {:#?}", ast); }
if verbose == true { println!("Parsed AstNode: {:#?}", ast); }
let eval_start = Instant::now();
match evaluator::evaluate(&ast) {
Ok(answer) => {
let eval_time = Instant::now().duration_since(eval_start).as_nanos() as f32;
if debug == true {
if verbose == true {
println!("Evaluated value: {} {:?}", answer.value, answer.unit);
println!("\u{23f1} {:.3}ms lexing", lex_time/1000.0/1000.0);
println!("\u{23f1} {:.3}ms parsing", parse_time/1000.0/1000.0);

View File

@ -5,14 +5,14 @@ use cpc::units::Unit;
fn main() {
use std::env;
let args: Vec<String> = env::args().collect();
let mut debug = false;
if args.iter().any(|i| i=="--debug") {
debug = true;
let mut verbose = false;
if args.iter().any(|i| i == "-v" || i == "--verbose") {
verbose = true;
}
if args.len() >= 2 {
match eval(&args[1], true, Unit::Celsius, debug) {
match eval(&args[1], true, Unit::Celsius, verbose) {
Ok(answer) => {
if !debug {
if !verbose {
println!("{} {:?}", answer.value, answer.unit)
}
},