Skip to content

oxc-project/bench-javascript-transformer-written-in-rust

Repository files navigation

Transformer Benchmark for Oxc and Swc

A transformer is also known as a transpiler, similar to Babel transform.

The purpose of this benchmark is for people who wants to evaluate and compare the performance characteristics of the two transformer.

The benchmark measures the whole parse -> transform -> codegen pipeline as a real-word scenario.

The numbers indicate that Oxc is at least 3 times faster than Swc.

Results

Codspeed

CodSpeed Badge

Codspeed measures performance by cpu instructions.

Target lowering to es2015

cal.com.tsx

oxc swc
no-drop 12.8 ms (1.00x) 44.5 ms (3.46x)
parallel 22.8 ms (1.00x) 117.4 ms (5.14x)
single-thread 12.3 ms (1.00x) 44.6 ms (3.63x)

typescript.js

oxc swc
no-drop 91.1 ms (1.00x) 363.8 ms (3.99x)
parallel 146.9 ms (1.00x) 770.5 ms (5.24x)
single-thread 90.2 ms (1.00x) 370.2 ms (4.11x)

Run benchmark locally

Run the following command on your machine for replication.

cargo bench

Generate the table

pnpm i
pnpm run table

Maximum Resident Set Size

./memory.sh

./files/cal.com.tsx
oxc 26.3 mb
swc 30.9 mb

./files/typescript.js
oxc 137.8 mb
swc 148.5 mb

Setup

  • Uses mimalloc as the global allocator
  • Uses the following release profile
[profile.release]
opt-level     = 3
lto           = "fat"
codegen-units = 1
strip         = "symbols"
debug         = false
panic         = "abort"

single-thread

This is the standard benchmark run in a single thread.

group.bench_with_input(id, &source, |b, source| {
    b.iter(|| Self::run(source))
});

no-drop

This uses the iter_with_large_drop function, which does not take AST drop time into account.

AST drop time can become a bottleneck in applications such as as bundler, where there are a few thousands of files need to be parsed.

group.bench_with_input(id, &source, |b, source| {
    b.iter_with_large_drop(|| Self::run(source))
});

parallel

This benchmark uses the total number of physical cores as the total number of files to parse per bench iteration. For example it parses 6 files in parallel on my Mac i7 6 cores.

This can indicate the existence of resource contention.

let cpus = num_cpus::get_physical();
group.bench_with_input(id, &source, |b, source| {
    b.iter(|| {
        (0..cpus).into_par_iter().for_each(|_| {
            Self::run(source);
        });
    })
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •