Skip to content

Commit 0fb223a

Browse files
author
Silviu Caragea
committed
Better way to benchmark
1 parent ab9d001 commit 0fb223a

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ endif
2020

2121
include $(C_SRC_ENV)
2222

23+
# benchmarks
24+
25+
BENCH_PROFILE_ARGS=-pa _build/bench/lib/epqueue/benchmarks -pa _build/bench/lib/*/ebin -noshell
26+
ELEMENTS=1000000
27+
MAX_PRIORITY=1000000
28+
USE_LOCK=false
29+
PROCS=1
30+
31+
setup_benchmark:
32+
${REBAR} as bench compile
33+
34+
bench_serial: setup_benchmark
35+
erl $(BENCH_PROFILE_ARGS) -eval "benchmark:benchmark_serial($(ELEMENTS), $(MAX_PRIORITY), $(USE_LOCK))" -eval "init:stop()."
36+
37+
bench_concurrent: setup_benchmark
38+
erl $(BENCH_PROFILE_ARGS) -eval "benchmark:benchmark_concurrent($(PROCS), $(ELEMENTS), $(MAX_PRIORITY))" -eval "init:stop()."
39+
40+
# common tests
41+
2342
ct:
2443
mkdir -p log
2544
${REBAR} ct --compile_only
@@ -29,6 +48,8 @@ ct:
2948
-pa $(ROOT_TEST)/*/ebin \
3049
-logdir log
3150

51+
# cpplint and cppcheck
52+
3253
cpplint:
3354
cpplint --counting=detailed \
3455
--filter=-legal/copyright,-build/include_subdir,-build/include_order,-whitespace/blank_line,-whitespace/braces,-whitespace/indent,-whitespace/parens,-whitespace/newline \

README.md

+16-17
Original file line numberDiff line numberDiff line change
@@ -66,37 +66,36 @@ In order to run the integrity tests run `make ct` from project root.
6666
Performance testing
6767
-----------
6868

69-
From the `test` folder you can use the `benchmark:benchmark_serial(NrElements, MaxPriority, UseLock)` or `benchmark:benchmark_concurrent(NrProcs, NrElements, MaxPriority)` methods to test the performances.
69+
Results are generated on a MacBook Pro (Intel Core i7 4 cores at 2.5 GHz):
70+
The `insert overhead` is the time spent to generate `ELEMENTS` random numbers for the priorities,
7071

71-
- `benchmark_serial/3` inserts a number of `NrElements` with priorities from 0 to `MaxPriority` in a queue that use or not a lock.
72-
- `benchmark_concurrent/3` spawn a number of `NrProcs` processes that will insert a number of `NrElements` with priorities from 0 to `MaxPriority` in a queue that is mandatory to use a lock.
73-
74-
Results on MacBook Pro (Intel Core i7 4 cores at 2.5 GHz):
72+
- `make bench_serial` inserts a number of `ELEMENTS` with priorities from 0 to `MAX_PRIORITY` in a queue that
73+
use or not a lock.
7574

7675
```erl
77-
benchmark:benchmark_serial(1000000, 1000000, true).
78-
insert overhead: 252.764 ms insert time: 740.722 ms pop time: 1833.721 ms
76+
make bench_serial ELEMENTS=1000000 MAX_PRIORITY=10000000 USE_LOCK=true
77+
insert overhead: 252.764 ms insert time: 740.722 ms pop time: 1833.721 ms
7978

80-
benchmark:benchmark_serial(1000000, 1000000, false).
81-
insert overhead: 250.178 ms insert time: 726.999 ms pop time: 1771.064 ms
79+
make bench_serial ELEMENTS=1000000 MAX_PRIORITY=10000000 USE_LOCK=false
80+
insert overhead: 250.178 ms insert time: 726.999 ms pop time: 1771.064 ms
8281
```
8382

84-
The overhead is the time spent to generate `NrElements` random numbers for the priorities,
83+
- `bench_concurrent` spawn a number of `PROCS` processes that will insert a number of `ELEMENTS` with priorities
84+
from 0 to `MAX_PRIORITY` in a queue (lock is mandatory).
8585

8686
```erl
87-
benchmark:benchmark_concurrent(1, 1000000, 1000000).
88-
insert overhead: 274.339 ms insert time: 778.185 ms pop time: 1772.712 ms
87+
make bench_concurrent PROCS=1 ELEMENTS=1000000 MAX_PRIORITY=10000000
88+
insert overhead: 274.339 ms insert time: 778.185 ms pop time: 1772.712 ms
8989

90-
benchmark:benchmark_concurrent(2, 1000000, 1000000).
90+
make bench_concurrent PROCS=2 ELEMENTS=1000000 MAX_PRIORITY=10000000
9191
insert overhead: 139.748 ms insert time: 2408.561 ms pop time: 4563.286 ms
9292

93-
benchmark:benchmark_concurrent(3, 1000000, 1000000).
93+
make bench_concurrent PROCS=3 ELEMENTS=1000000 MAX_PRIORITY=10000000
9494
insert overhead: 100.252 ms insert time: 3528.367 ms pop time: 4913.981 ms
9595

96-
benchmark:benchmark_concurrent(4, 1000000, 1000000).
96+
make bench_concurrent PROCS=4 ELEMENTS=1000000 MAX_PRIORITY=10000000
9797
insert overhead: 77.775 ms insert time: 3603.385 ms pop time: 5055.776 ms
9898

99-
benchmark:benchmark_concurrent(20, 1000000, 1000000).
99+
make bench_concurrent PROCS=20 ELEMENTS=1000000 MAX_PRIORITY=10000000
100100
insert overhead: 76.704 ms insert time: 3676.474 ms pop time: 5039.594 ms
101101
```
102-
File renamed without changes.
File renamed without changes.

rebar.config

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
]}.
1818

1919
{profiles, [
20+
{bench, [
21+
{extra_src_dirs, ["benchmarks"]}
22+
]},
2023
{test, [
2124
{erl_opts, [
2225
debug_info,

0 commit comments

Comments
 (0)