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

-behaviour(edis_bench).

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

-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([sadd/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) ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY], group = keys, 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 sadd([binary()]) -> pos_integer().
sadd(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"SADD">>, args = [?KEY | Keys],
                  group = sets, result_type = number}).<commit_msg>SADD, SCARD & SDIFF benchmarked<commit_after>%%%-------------------------------------------------------------------
%%% @author <NAME> <<EMAIL>>
%%% @author <NAME> <<EMAIL>>
%%% @copyright (C) 2011 InakaLabs SRL
%%% @doc Benchmarks for sets commands
%%% @end
%%%-------------------------------------------------------------------
-module(sets_bench).
-author('<NAME> <<EMAIL>>').
-author('<NAME> <<EMAIL>>').

-behaviour(edis_bench).

-define(KEY, <<"test-set">>).
-define(KEY2, <<"test-set2">>).

-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([sadd/1, scard/1, sdiff/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(scard, Keys) -> sadd(Keys), ok;
init_per_round(sdiff, Keys) ->
  edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"SADD">>,
                  args = [?KEY2 | lists:map(fun edis_util:integer_to_binary/1, lists:seq(1, 100))],
                  group = sets, result_type = number}),
  sadd(Keys),
  ok;
init_per_round(_Fun, _Keys) ->
  _ = edis_db:run(
        edis_db:process(0),
        #edis_command{cmd = <<"DEL">>, args = [?KEY], group = keys, 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 sadd([binary()]) -> pos_integer().
sadd(Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"SADD">>, args = [?KEY | Keys],
                  group = sets, result_type = number}).

-spec scard([binary()]) -> pos_integer().
scard(_Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"SCARD">>, args = [?KEY], group = sets, result_type = number}).

-spec sdiff([binary()]) -> [binary()].
sdiff(_Keys) ->
  catch edis_db:run(
    edis_db:process(0),
    #edis_command{cmd = <<"SDIFF">>, args = [?KEY, ?KEY2], group = sets, result_type = multi_bulk}).
{'fraction_non_alphanumeric': 0.3131561313379495, 'fraction_numerical': 0.009828009828009828, 'mean_word_length': 2.870354364736387, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7125630', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1542, 'n_words': 293}