From 35dac296f662e6984f00d58c2ebf6a3881f3ea63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 19 Jul 2024 13:10:17 +0900 Subject: [PATCH] Use swc alloc --- crates/swc_ecma_codegen/benches/bench.rs | 5 ++++- crates/swc_ecma_codegen/benches/with_parse.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index a164b9f16135..b6f16b6c0c3a 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -1,7 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_allocator::maybe::vec::Vec; +use swc_allocator::{maybe::vec::Vec, Allocator}; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -95,6 +95,9 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { + let allocator = Allocator::default(); + let _guard = unsafe { allocator.guard() }; + let mut src_map_buf = Vec::new(); let mut buf = Vec::new(); { diff --git a/crates/swc_ecma_codegen/benches/with_parse.rs b/crates/swc_ecma_codegen/benches/with_parse.rs index f4088e458c89..7d7e86502ca4 100644 --- a/crates/swc_ecma_codegen/benches/with_parse.rs +++ b/crates/swc_ecma_codegen/benches/with_parse.rs @@ -1,7 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_allocator::maybe::vec::Vec; +use swc_allocator::{maybe::vec::Vec, Allocator}; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -83,6 +83,9 @@ const LARGE_PARTIAL_JS: &str = include_str!("large-partial.js"); fn bench_emitter(b: &mut Bencher, s: &str) { let _ = ::testing::run_test(true, |cm, handler| { b.iter(|| { + let allocator = Allocator::default(); + let _guard = unsafe { allocator.guard() }; + let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); let module = parser