Skip to content

Commit

Permalink
refactor: set bench prints only show on debug
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Jun 12, 2024
1 parent b971500 commit c13f074
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use std::fs::File;
use std::io::prelude::*;
use std::path::Path;

use astgen::{Parser, AST};
use astgen::AST;
use clap::{Arg, Command};
use codegen::cranelift_JIT::save_executable;
use codegen::cranelift_JIT::JIT;
// use codegen::JIT;
use core::mem;
Expand Down Expand Up @@ -78,17 +79,23 @@ fn main() {
let end_time_new_new = std::time::Instant::now();
let duration_new_new = end_time_new_new.duration_since(start_time_new_new);
let new_new_tokens = new_new_lexer.get_tokens();
#[cfg(debug_assertions)]
println!("New New Lexer Time: {:?}", duration_new_new);

//println!("New Tokens: {:?}", new_tokens);
// let start_time_old = std::time::Instant::now();
// let tokens = lexer(&contents);
// let end_time_old = std::time::Instant::now();
// let duration_old = end_time_old.duration_since(start_time_old);

#[cfg(debug_assertions)]
println!("New Lexer Time: {:?}", duration_new);
// println!("Old Lexer Time: {:?}", duration_old);

#[cfg(debug_assertions)]
{
for token in &new_tokens {
// println!("{}", token);
}
}
// calulate how times faster the new lexer is
// let speedup = duration_old.as_nanos() as f64 / duration_new.as_nanos() as f64;
// println!("Speedup: {}x", speedup);
Expand All @@ -100,11 +107,13 @@ fn main() {
let new_chars_mb_per_second = new_chars_per_second * 4.0 / 1024.0 / 1024.0;
let new_new_chars_per_second = contents.len() as f64 / duration_new_new.as_secs_f64();
let new_new_chars_mb_per_second = new_new_chars_per_second * 4.0 / 1024.0 / 1024.0;
println!("New Chars Per Second: {}", new_chars_per_second);
println!("New Chars MB/s: {}", new_chars_mb_per_second);
println!("New New Chars Per Second: {}", new_new_chars_per_second);
println!("New New Chars MB/s: {}", new_new_chars_mb_per_second);

#[cfg(debug_assertions)]
{
println!("New Chars Per Second: {}", new_chars_per_second);
println!("New Chars MB/s: {}", new_chars_mb_per_second);
println!("New New Chars Per Second: {}", new_new_chars_per_second);
println!("New New Chars MB/s: {}", new_new_chars_mb_per_second);
}
// println!("New New Lexer Contents: {:?}", new_new_tokens);
// println!("New Lexer Contents: {:?}", new_tokens);

Expand All @@ -128,6 +137,7 @@ fn main() {
let ast_new = mid_ir.get_asts();

let duration_parser_new = end_time_parser_new.duration_since(start_time_parser_new);
#[cfg(debug_assertions)]
println!("New Parser Time: {:?}", duration_parser_new);

// let speedup = duration_parser_old.as_nanos() as f64 / duration_parser_new.as_nanos() as f64;
Expand All @@ -136,6 +146,7 @@ fn main() {
// let old_tokens_per_second = tokens.len() as f64 / duration_parser_old.as_secs_f64();
// println!("Old Tokens Per Second: {}", old_tokens_per_second);
let new_tokens_per_second = new_tokens.len() as f64 / duration_parser_new.as_secs_f64();
#[cfg(debug_assertions)]
println!("New Tokens Per Second: {}", new_tokens_per_second);

//let old_tokens_mb_per_second = old_tokens_per_second / 1024.0 / 1024.0;
Expand Down Expand Up @@ -176,21 +187,25 @@ fn main() {
// generate_ir(ast_new);
let start_time_jit = std::time::Instant::now();
let mut jit = JIT::default();
#[cfg(debug_assertions)]
println!("JIT: ");
let code_ptr = jit.compile(ast_new.clone(), input, false);
#[cfg(debug_assertions)]
println!("JIT Compiled");
let end_time_jit = std::time::Instant::now();
let duration_jit = end_time_jit.duration_since(start_time_jit);
#[cfg(debug_assertions)]
println!("JIT Compile Time: {:?}", duration_jit);
println!();
let pre_run_time = std::time::Instant::now();
let result = run(code_ptr.unwrap()).unwrap();
let result = run(code_ptr.clone().unwrap()).unwrap();
let duration = std::time::Instant::now().duration_since(pre_run_time);
println!(
"exit with code {} in {:?}",
result,
duration + duration_jit + duration_new_new + duration_parser_new
);
let _ = save_executable(code_ptr.unwrap(), "a");
let _ = drop(jit);
let _ = drop(new_new_lexer);
let _ = drop(new_lexer);
Expand Down

0 comments on commit c13f074

Please sign in to comment.