<commit_before>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2011 InakaLabs SRL
%%% @doc Benchmarks for lists commands
%%% @end
%%%-------------------------------------------------------------------
-module(lists_bench).
-author('<NAME> <<EMAIL>>').
-author('<NAME> <<EMAIL>>').

-behaviour(edis_bench).

-define(KEY, <<"test-list">>).

-include("edis.hrl").

-export([all/0,
         init/0, init_per_testcase/1, init_per_round/2,
         quit/0, quit_per_testcase/1, quit_per_round/2]).
-export([blpop/1, blpop_nothing/1, brpop/1, brpop_nothing/1]).

%% ====================================================================
%% External functions
%% ====================================================================
-spec all() -> [atom()].
all() -> [Fun || {Fun, _} <- ?MODULE:module_info(exports) -- edis_bench:behaviour_info(callbacks),
                 Fun =/= module_info].

-spec init() -> ok.
init() -> ok.

-spec quit() -> ok.
quit() -> ok.

-spec init_per_testcase(atom()) -> ok.
init_per_testcase(_Function) -> ok.

-spec quit_per_testcase(atom()) -> ok.
quit_per_testcase(_Function) -> ok.

-spec init_per_round(atom(), [binary()]) -> ok.
init_per_round(Fun, Keys) when Fun =:= blpop_nothing;
                               Fun =:= brpop_nothing ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY | Keys], group = keys, result_type = number}),
  ok;
init_per_round(_Fun, Keys) ->
  _ =
    edis_db:run(
      edis_db:process(0),
      #edis_command{cmd = <<"LPUSH">>, args = [?KEY | Keys], group = lists, result_type = number}),
  ok.

-spec quit_per_round(atom(), [binary()]) -> ok.
quit_per_round(_, _Keys) ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY], group = keys, result_type = number}
        ),
  ok.

-spec blpop_nothing([binary()]) -> timeout.
blpop_nothing(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BLPOP">>, args = Keys,
                  timeout = 10, expire = edis_util:now(),
                  group = lists, result_type = multi_bulk}, 10).

-spec blpop([binary()]) -> undefined.
blpop(_Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BLPOP">>, args = [?KEY],
                  timeout = 1000, expire = edis_util:now() + 1,
                  group = lists, result_type = multi_bulk}, 1000).

-spec brpop_nothing([binary()]) -> timeout.
brpop_nothing(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BRPOP">>, args = Keys,
                  timeout = 10, expire = edis_util:now(),
                  group = lists, result_type = multi_bulk}, 10).

-spec brpop([binary()]) -> undefined.
brpop(_Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BRPOP">>, args = [?KEY],
                  timeout = 1000, expire = edis_util:now() + 1,
                  group = lists, result_type = multi_bulk}, 1000).<commit_msg>BRPOPLPUSH benchmarked<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2011 InakaLabs SRL
%%% @doc Benchmarks for lists commands
%%% @end
%%%-------------------------------------------------------------------
-module(lists_bench).
-author('<NAME> <<EMAIL>>').
-author('<NAME> <<EMAIL>>').

-behaviour(edis_bench).

-define(KEY, <<"test-list">>).

-include("edis.hrl").

-export([all/0,
         init/0, init_per_testcase/1, init_per_round/2,
         quit/0, quit_per_testcase/1, quit_per_round/2]).
-export([blpop/1, blpop_nothing/1, brpop/1, brpop_nothing/1, brpoplpush/1]).

%% ====================================================================
%% External functions
%% ====================================================================
-spec all() -> [atom()].
all() -> [Fun || {Fun, _} <- ?MODULE:module_info(exports) -- edis_bench:behaviour_info(callbacks),
                 Fun =/= module_info].

-spec init() -> ok.
init() -> ok.

-spec quit() -> ok.
quit() -> ok.

-spec init_per_testcase(atom()) -> ok.
init_per_testcase(_Function) -> ok.

-spec quit_per_testcase(atom()) -> ok.
quit_per_testcase(_Function) -> ok.

-spec init_per_round(atom(), [binary()]) -> ok.
init_per_round(Fun, Keys) when Fun =:= blpop_nothing;
                               Fun =:= brpop_nothing ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY | Keys], group = keys, result_type = number}),
  ok;
init_per_round(_Fun, Keys) ->
  _ =
    edis_db:run(
      edis_db:process(0),
      #edis_command{cmd = <<"LPUSH">>, args = [?KEY | Keys], group = lists, result_type = number}),
  ok.

-spec quit_per_round(atom(), [binary()]) -> ok.
quit_per_round(_, _Keys) ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY], group = keys, result_type = number}
        ),
  ok.

-spec blpop_nothing([binary()]) -> timeout.
blpop_nothing(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BLPOP">>, args = Keys,
                  timeout = 10, expire = edis_util:now(),
                  group = lists, result_type = multi_bulk}, 10).

-spec blpop([binary()]) -> undefined.
blpop(_Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BLPOP">>, args = [?KEY],
                  timeout = 1000, expire = edis_util:now() + 1,
                  group = lists, result_type = multi_bulk}, 1000).

-spec brpop_nothing([binary()]) -> timeout.
brpop_nothing(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BRPOP">>, args = Keys,
                  timeout = 10, expire = edis_util:now(),
                  group = lists, result_type = multi_bulk}, 10).

-spec brpop([binary()]) -> undefined.
brpop(_Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BRPOP">>, args = [?KEY],
                  timeout = 1000, expire = edis_util:now() + 1,
                  group = lists, result_type = multi_bulk}, 1000).

-spec brpoplpush([binary()]) -> undefined.
brpoplpush(_Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"BRPOPLPUSH">>, args = [?KEY, <<(?KEY)/binary, "-2">>],
                  timeout = 1000, expire = edis_util:now() + 1,
                  group = lists, result_type = bulk}, 1000).
{'fraction_non_alphanumeric': 0.26204447189623226, 'fraction_numerical': 0.016676961087090797, 'mean_word_length': 2.6326416152551877, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5808751', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2203, 'n_words': 431}