mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 15:30:00 -04:00
benches and generic infection
This commit is contained in:
parent
2f7d2fa043
commit
633d0f17fc
11 changed files with 1113 additions and 204 deletions
|
@ -37,34 +37,42 @@ fn dorewrite(data: &str) -> Result<RewriteResult> {
|
|||
.context("failed to rewrite file")
|
||||
}
|
||||
|
||||
fn dobench(data: String) {
|
||||
loop {
|
||||
let _ = dorewrite(&data);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let file = env::args().nth(1).unwrap_or_else(|| "test.js".to_string());
|
||||
let data = fs::read_to_string(file).context("failed to read file")?;
|
||||
let bench = env::args().nth(2).is_some();
|
||||
|
||||
if bench {
|
||||
loop {
|
||||
dorewrite(&data)?;
|
||||
for _ in 0..15 {
|
||||
let data = data.clone();
|
||||
std::thread::spawn(move || dobench(data));
|
||||
}
|
||||
dobench(data);
|
||||
} else {
|
||||
let res = dorewrite(&data)?;
|
||||
|
||||
let source = Arc::new(
|
||||
NamedSource::new(data, "https://google.com/glorngle/si.js").with_language("javascript"),
|
||||
);
|
||||
eprintln!("errors:");
|
||||
for err in res.errors {
|
||||
eprintln!("{}", err.with_source_code(source.clone()));
|
||||
}
|
||||
|
||||
println!("changes: {:#?}", res.changes);
|
||||
|
||||
println!(
|
||||
"rewritten:\n{}",
|
||||
String::from_utf8(res.js).context("failed to parse rewritten js")?
|
||||
);
|
||||
}
|
||||
|
||||
let res = dorewrite(&data)?;
|
||||
|
||||
let source = Arc::new(
|
||||
NamedSource::new(data, "https://google.com/glorngle/si.js").with_language("javascript"),
|
||||
);
|
||||
eprintln!("errors:");
|
||||
for err in res.errors {
|
||||
eprintln!("{}", err.with_source_code(source.clone()));
|
||||
}
|
||||
|
||||
println!("changes: {:#?}", res.changes);
|
||||
|
||||
println!(
|
||||
"rewritten:\n{}",
|
||||
String::from_utf8(res.js).context("failed to parse rewritten js")?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue