From b2f8e7138abb356d990fb7f79f03efa8bd6d7fd4 Mon Sep 17 00:00:00 2001 From: Ivan Plesskih Date: Tue, 2 Jun 2020 19:51:32 +0500 Subject: [PATCH] Added jemalloc feature for benchmark --- README.md | 11 +++++++++++ benchmark/Cargo.toml | 4 ++++ benchmark/src/lib.rs | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 264f12ec..f5092486 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,18 @@ Ensure that there is no CPU-heavy process in background! ```shell script cd benchmark + +#measure all with system malloc cargo bench + +#measure only chat run +cargo bench -- "chat run" + +#measure all with jemalloc +cargo bench --features jemalloc + +#measure only simple run with jemalloc +cargo bench --features jemalloc -- "simple run" ``` Now HTML report is available at `benchmark/target/criterion/report` diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index 8d217831..e807dc32 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -10,12 +10,16 @@ futures = "0.3.4" serde_json = "*" async-graphql-parser = { path = "../async-graphql-parser" } async-graphql = { path = ".." } +jemallocator = { version = "0.3.2", optional = true } [dev-dependencies] criterion = "0.3" simple = { path = "simple" } chat = { path = "chat" } +[features] +jemalloc = ["jemallocator"] + [[bench]] name = "simple" harness = false diff --git a/benchmark/src/lib.rs b/benchmark/src/lib.rs index bc438f9c..d6462c9b 100644 --- a/benchmark/src/lib.rs +++ b/benchmark/src/lib.rs @@ -3,6 +3,10 @@ use async_graphql::{ObjectType, QueryResponse, Schema, SubscriptionType}; use async_graphql_parser::{parse_query, query::Document}; use async_std::task; +#[cfg(feature = "jemalloc")] +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + pub fn run( s: &Schema, q: &str,