diff --git a/README.md b/README.md index aca600a2..c9ccdc35 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,21 @@ Requires OTP 21.3 of above. ## Design +## Benchmarks + +Running benchmarks is done with [benchee](https://github.com/bencheeorg/benchee). Benchmark functions are in modules under `samples/`. To run them open a rebar3 shell in the `bench` profile: + +``` shell +$ rebar3 as bench compile + +> ot_benchmarks:run(). +``` + +If an Elixir script is wanted for the benchmarks they could be run like: + +``` shell +$ ERL_LIBS=_build/bench/lib/ mix run --no-mix-exs samples/run.exs +``` + ## Contributing diff --git a/rebar.config b/rebar.config index 3b144b59..def4df8b 100644 --- a/rebar.config +++ b/rebar.config @@ -7,7 +7,12 @@ {profiles, [{test, [{erl_opts, [nowarn_export_all]}, - {ct_opts, [{ct_hooks, [cth_surefire]}]}]}]}. + {ct_opts, [{ct_hooks, [cth_surefire]}]}]}, + + {bench, [{deps, [benchee]}, + {extra_src_dirs, ["samples"]}, + {plugins, [rebar_mix]}, + {provider_hooks, [{pre, [{compile, {mix, find_elixir_libs}}]}]}]}]}. {xref_checks, [undefined_function_calls, undefined_functions, deprecated_function_calls, deprecated_functions]}. diff --git a/samples/ot_benchmarks.erl b/samples/ot_benchmarks.erl new file mode 100644 index 00000000..2c37b0db --- /dev/null +++ b/samples/ot_benchmarks.erl @@ -0,0 +1,29 @@ +%%%------------------------------------------------------------------------ +%% Copyright 2019, OpenTelemetry Authors +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% @doc +%% @end +%%%------------------------------------------------------------------------- +-module(ot_benchmarks). + +-export([run/0]). + +run() -> + Iterations = 100, + PDictCtxFun = fun() -> + [ot_tracer:start_span(<<"span-", (integer_to_binary(X))/binary>>) + || X <- lists:seq(1, 100)] + end, + benchee:run(#{<<"pdict_ctx">> => PDictCtxFun}), + ok.