Skip to content

Commit

Permalink
benches and generic infection
Browse files Browse the repository at this point in the history
  • Loading branch information
r58Playz committed Dec 11, 2024
1 parent 2f7d2fa commit 633d0f1
Show file tree
Hide file tree
Showing 11 changed files with 1,119 additions and 210 deletions.
320 changes: 318 additions & 2 deletions rewriter/Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions rewriter/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ urlencoding = "2.1.3"

[dev-dependencies]
boa_engine = "0.20.0"
criterion = "0.5.1"

[[bench]]
name = "samples"
harness = false
62 changes: 62 additions & 0 deletions rewriter/native/benches/samples.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use rewriter::{cfg::Config, rewrite};
use std::str::FromStr;
use url::Url;
use urlencoding::encode;

fn encode_string(str: String) -> String {
encode(&str).to_string()
}

pub fn bench(c: &mut Criterion) {
let discord = include_str!("../sample/discord.js");
let google = include_str!("../sample/google.js");

let cfg = Config {
prefix: "/scrammedjet/".to_string(),
encoder: Box::new(encode_string),

base: Url::from_str("https://google.com/glorngle/si.js").expect("invalid base"),
sourcetag: "glongle1".to_string(),

wrapfn: "$wrap".to_string(),
wrapthisfn: "$gwrap".to_string(),
importfn: "$import".to_string(),
rewritefn: "$rewrite".to_string(),
metafn: "$meta".to_string(),
setrealmfn: "$setrealm".to_string(),
pushsourcemapfn: "$pushsourcemap".to_string(),

capture_errors: true,
do_sourcemaps: true,
scramitize: false,
strict_rewrites: true,
};

c.bench_with_input(
BenchmarkId::new("rewrite/samples", "discord"),
&(discord, cfg.clone()),
|b, input| {
b.iter_batched(
|| input.clone(),
|x| rewrite(x.0, x.1),
BatchSize::SmallInput,
)
},
);

c.bench_with_input(
BenchmarkId::new("rewrite/samples", "google"),
&(google, cfg.clone()),
|b, input| {
b.iter_batched(
|| input.clone(),
|x| rewrite(x.0, x.1),
BatchSize::SmallInput,
)
},
);
}

criterion_group!(samples, bench);
criterion_main!(samples);
Loading

0 comments on commit 633d0f1

Please sign in to comment.