Skip to content

Commit

Permalink
Merge pull request #6 from tsloughter/benchmarker
Browse files Browse the repository at this point in the history
add benchmarking example
  • Loading branch information
tsloughter authored Aug 16, 2019
2 parents 7a131de + b9215a2 commit fd614e3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 6 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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]}.
Expand Down
29 changes: 29 additions & 0 deletions samples/ot_benchmarks.erl
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit fd614e3

Please sign in to comment.