Commits

arkdro  committed 6a67ac1

add test that is to be used in profiling

  • Participants
  • Parent commits 2b86332

Comments (0)

Files changed (1)

File erlang/src/test1.erl

+%%% @doc switch on round_trip mode, send numbers to c_server,
+%%% receive stub results
+-module(test1).
+-export([run/1, run2/2]).
+
+run2(Len, Cmd) ->
+    application:set_env(odeci, port_command, Cmd),
+    c_server:start_link(),
+    timer:sleep(2000),
+    run(Len).
+
+run(Len) ->
+    c_server:rr_on(),
+    r2(Len),
+    c_server:rr_off(),
+    ok.
+
+%%==================================================================
+%% Internal functions
+%%==================================================================
+
+r2(N) ->
+    r2(N, 0).
+
+r2(0, _) ->
+    ok;
+r2(N, Cnt) ->
+    New = do_one_op(Cnt),
+    r2(N-1, New).
+
+do_one_op(Cnt) ->
+    N1 = gen_decimal(Cnt),
+    N2 = gen_decimal(Cnt+1),
+    c_server:add(N1, N2),
+    Cnt+2.
+
+gen_decimal(Cnt) ->
+    Sign = Cnt rem 2,
+    Exp = Cnt rem 100,
+    Mant = Cnt,
+    {Sign, Mant, Exp}.