mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
chore(resolver): add more data to benchmark (#586)
This commit is contained in:
parent
378505f244
commit
ca96ff84a6
1 changed files with 59 additions and 29 deletions
|
|
@ -25,45 +25,75 @@ fn data() -> Vec<(PathBuf, &'static str)> {
|
|||
vec![
|
||||
(cwd.clone(), "./"),
|
||||
(cwd.clone(), "./lib/index"),
|
||||
(cwd.join("./test/fixtures/extensions"), "./foo"),
|
||||
// query fragment
|
||||
(cwd.join("test/fixtures"), "./main1.js#fragment?query"),
|
||||
(cwd.join("test/fixtures"), "m1/a.js?query#fragment"),
|
||||
// extensions
|
||||
(cwd.join("test/fixtures/extensions"), "./foo"),
|
||||
(cwd.join("test/fixtures/extensions/module"), "module"),
|
||||
// browserField
|
||||
(cwd.join("test/fixtures/browser-module"), "./lib/replaced"),
|
||||
(cwd.join("test/fixtures/browser-module/lib"), "./replaced"),
|
||||
// extensionAlias
|
||||
(cwd.join("test/fixtures/extension-alias"), "./index.js"),
|
||||
// scoped
|
||||
(cwd.join("test/fixtures/scoped"), "@scope/pack1"),
|
||||
(cwd.join("test/fixtures/scoped"), "@scope/pack2/lib"),
|
||||
]
|
||||
}
|
||||
|
||||
fn nodejs_resolver() -> nodejs_resolver::Resolver {
|
||||
use nodejs_resolver::{Options, Resolver};
|
||||
Resolver::new(Options {
|
||||
browser_field: true,
|
||||
extension_alias: vec![
|
||||
(".js".into(), vec![".ts".into(), ".js".into()]),
|
||||
(".mjs".into(), vec![".mts".into()]),
|
||||
],
|
||||
..Options::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn oxc_resolver() -> oxc_resolver::Resolver {
|
||||
use oxc_resolver::{ResolveOptions, Resolver};
|
||||
Resolver::new(ResolveOptions {
|
||||
alias_fields: vec!["browser".into()],
|
||||
extension_alias: vec![
|
||||
(".js".into(), vec![".ts".into(), ".js".into()]),
|
||||
(".mjs".into(), vec![".mts".into()]),
|
||||
],
|
||||
..ResolveOptions::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn resolver_benchmark(c: &mut Criterion) {
|
||||
let data = data();
|
||||
|
||||
// bench nodejs_resolver
|
||||
{
|
||||
let resolver = nodejs_resolver::Resolver::new(nodejs_resolver::Options::default());
|
||||
// Check path is valid
|
||||
for (path, request) in &data {
|
||||
assert!(resolver.resolve(path, request).is_ok(), "{path:?} {request}");
|
||||
}
|
||||
c.bench_with_input(BenchmarkId::new("nodejs_resolver", ""), &data, |b, data| {
|
||||
b.iter(|| {
|
||||
for (path, request) in data {
|
||||
_ = resolver.resolve(path, request);
|
||||
}
|
||||
});
|
||||
});
|
||||
// Check path is valid, re-initlize so it they don't use cache
|
||||
for (path, request) in &data {
|
||||
assert!(nodejs_resolver().resolve(path, request).is_ok(), "{path:?} {request}");
|
||||
assert!(oxc_resolver().resolve(path, request).is_ok(), "{path:?} {request}");
|
||||
}
|
||||
|
||||
// bench oxc_resolver
|
||||
{
|
||||
let resolver = oxc_resolver::Resolver::default();
|
||||
// Check path is valid
|
||||
for (path, request) in &data {
|
||||
assert!(resolver.resolve(path, request).is_ok(), "{path:?} {request}");
|
||||
}
|
||||
c.bench_with_input(BenchmarkId::new("oxc_resolver", ""), &data, |b, data| {
|
||||
b.iter(|| {
|
||||
for (path, request) in data {
|
||||
_ = resolver.resolve(path, request);
|
||||
}
|
||||
});
|
||||
// Bench nodejs_resolver with cache
|
||||
c.bench_with_input(BenchmarkId::new("nodejs_resolver", ""), &data, |b, data| {
|
||||
let nodejs_resolver = nodejs_resolver();
|
||||
b.iter(|| {
|
||||
for (path, request) in data {
|
||||
_ = nodejs_resolver.resolve(path, request);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Bench oxc_resolver with cache
|
||||
c.bench_with_input(BenchmarkId::new("oxc_resolver", ""), &data, |b, data| {
|
||||
let oxc_resolver = oxc_resolver();
|
||||
b.iter(|| {
|
||||
for (path, request) in data {
|
||||
_ = oxc_resolver.resolve(path, request);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, resolver_benchmark);
|
||||
|
|
|
|||
Loading…
Reference in a new issue