diff --git a/README.md b/README.md index 132130fd..07d76dea 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,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,