Permalink
Browse files

Almost empty benchmarking project.

  • Loading branch information...
0 parents commit 39c7da57345216a226b91454ec297e9f31fc0c13 @jlouis committed Feb 16, 2011
Showing with 209 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +12 −0 Makefile
  3. +8 −0 ebin/myapp.app
  4. +21 −0 rebar.config
  5. +2 −0 src/Makefile
  6. +108 −0 src/bench_map.erl
  7. +12 −0 src/myapp.app.src
  8. +16 −0 src/myapp_app.erl
  9. +28 −0 src/myapp_sup.erl
@@ -0,0 +1,2 @@
+*.beam
+.eunit
@@ -0,0 +1,12 @@
+.PHONY: all compile test clean
+
+all: compile
+
+compile:
+ rebar compile
+
+clean:
+ rebar clean
+
+test:
+ rebar eunit
@@ -0,0 +1,8 @@
+{application,myapp,
+ [{description,[]},
+ {vsn,"1"},
+ {registered,[]},
+ {applications,[kernel,stdlib]},
+ {mod,{myapp_app,[]}},
+ {env,[]},
+ {modules,[bench_map,myapp_app,myapp_sup]}]}.
@@ -0,0 +1,21 @@
+{erl_opts, [
+ %% bin_opt_info,
+ warn_format,
+ warn_export_all,
+ warn_export_vars,
+ warn_obsolete_guard,
+ %% warn_unused_import,
+ warn_bif_clash,
+ %% warn_missing_spec,
+ warn_untyped_record,
+ debug_info]}.
+
+{cover_enabled, true}.
+
+{dialyzer_opts, [{warnings, [error_handling,
+ race_conditions,
+ behaviours]}]}.
+
+{xref_checks, [undefined_function_calls,
+ locals_not_used,
+ exports_not_used]}.
@@ -0,0 +1,2 @@
+all:
+ cd .. && $(MAKE)
@@ -0,0 +1,108 @@
+-module(bench_map).
+
+-export([foo/0]).
+
+-ifdef(TEST).
+-include_lib("eqc/include/eqc.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-endif.
+
+foo() ->
+ foo.
+
+
+-ifdef(EUNIT).
+-ifdef(EQC).
+
+words() ->
+ Words = "/usr/share/dict/words",
+ {ok, Content} = file:read_file(Words),
+ binary:split(Content, <<"\n">>, [global]).
+
+list_shuffle(L) ->
+ random:seed(), %% Reset Random function
+ Laced = [{K, random:uniform()} || K <- L],
+ Sorted = lists:keysort(2, Laced),
+ [W || {W, _} <- Sorted].
+
+test_sets_words(Words, Set) ->
+ lists:foreach(
+ fun(Word) ->
+ true = sets:is_element(Word, Set)
+ end,
+ Words).
+
+test_gb_sets_words(Words, Set) ->
+ lists:foreach(
+ fun(Word) ->
+ true = gb_sets:is_element(Word, Set)
+ end,
+ Words).
+
+test_dict_words(Words, Dict) ->
+ lists:foreach(
+ fun(W) ->
+ true = dict:fetch(W, Dict)
+ end,
+ Words).
+
+test_gb_trees_words(Words, Tree) ->
+ lists:foreach(
+ fun(W) ->
+ true = gb_trees:is_defined(W, Tree)
+ end,
+ Words).
+
+test_map(Generator, TestFun) ->
+ Ws = words(),
+ S = Generator(Ws),
+ TestFun(Ws, S),
+ TestFun(lists:reverse(Ws), S),
+ TestFun(list_shuffle(Ws), S).
+
+set_test() ->
+ test_map(fun(Ws) ->
+ sets:from_list(Ws)
+ end,
+ fun test_sets_words/2).
+
+dict_test() ->
+ test_map(fun(Ws) ->
+ dict:from_list([{K, true} || K <- Ws])
+ end,
+ fun test_dict_words/2).
+
+gb_sets_test() ->
+ test_map(fun(Ws) ->
+ gb_sets:from_list(Ws)
+ end,
+ fun test_gb_sets_words/2).
+
+gb_trees_test() ->
+ test_map(fun(Ws) ->
+ lists:foldl(
+ fun(K, Tree) ->
+ gb_trees:enter(K, true, Tree)
+ end,
+ gb_trees:empty(),
+ Ws)
+ end,
+ fun test_gb_trees_words/2).
+
+-endif.
+-endif.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -0,0 +1,12 @@
+{application, myapp,
+ [
+ {description, ""},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, { myapp_app, []}},
+ {env, []}
+ ]}.
@@ -0,0 +1,16 @@
+-module(myapp_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ myapp_sup:start_link().
+
+stop(_State) ->
+ ok.
@@ -0,0 +1,28 @@
+
+-module(myapp_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+ {ok, { {one_for_one, 5, 10}, []} }.
+

0 comments on commit 39c7da5

Please sign in to comment.