SisMaker 2 years ago
parent
commit
1e83f56c43
4 changed files with 89 additions and 4 deletions
  1. +1
    -1
      src/compile/utKvsToBeam.erl
  2. +1
    -1
      src/compile/utStrToBeam.erl
  3. +1
    -1
      src/docs/erlang/erlang进程.md
  4. +86
    -1
      src/testCase/funTest.erl

+ 1
- 1
src/compile/utKvsToBeam.erl View File

@ -13,7 +13,7 @@ load(Module, KVs) ->
Forms = forms(Module, KVs),
{ok, Module, Bin} = compile:forms(Forms),
code:soft_purge(Module),
{module, Module} = code:load_binary(Module, atom_to_list(Module), Bin),
{module, Module} = code:load_binary(Module, [], Bin),
ok.
forms(Module, KVs) ->

+ 1
- 1
src/compile/utStrToBeam.erl View File

@ -8,4 +8,4 @@ load(Module, Export, Str) ->
{ok, Forms} = erl_parse:parse_form(Tokens),
NewForms = [{attribute, 1, module, Module}, {attribute, 2, export, Export}, Forms],
{ok, _, Binary} = compile:forms(NewForms),
code:load_binary(Module, "", Binary).
code:load_binary(Module, [], Binary).

+ 1
- 1
src/docs/erlang/erlang进程.md View File

@ -132,7 +132,7 @@ end
demonitor(MonitorRef, OptionList)
监视器与link不同的是它是单向式观察一些进程终止,各个监视器通过Erlang的引用相互区分,是调用monitor返回的,具有唯一性,
而且A进程可以设置多个对B进程的监视器,每一个通过不同的引用区分。
当被监视的进程终止时,一条格式{'Down',Reference, process, Pid, Reason}的消息会被发给监视此进程的进程
当被监视的进程终止时,一条格式{'DOWN',Reference, process, Pid, Reason}的消息会被发给监视此进程的进程
调用erlang:demonitor(Reference)可以移除监视器,
调用erlang:demonitor(Reference,[flush])可以让该监视进程邮箱中所有与Reference对应的{'DOWN', Reference,process,Pid,Reason}
的消息被冲刷掉。

+ 86
- 1
src/testCase/funTest.erl View File

@ -14,7 +14,7 @@ test2(A) ->
Fun1(A, A, A, A, A, Fun1).
test3(A) ->
[O * 2 || O <- A],
_ = [O * 2 || O <- A],
ok.
-define(types, [1, 1.1, [], [1], {1}, #{}, <<"123">>, self()]).
@ -66,6 +66,91 @@ ok(N) ->
test(A) ->
?IIF(lists:keyfind(a, 1, A), false, none, {_, V}, V).
ams1(A) -> ok.
ams2(A) -> fun() -> A end.
amf1(0, A, B, C, _) -> ok;
amf1(N, A, B, C, _) ->
amf1(N - 1, A, B, C, 1) .
amf2(0, A, B, C, _) -> ok;
amf2(N, A, B, C, _) ->
Fun = fun(One1) -> X = (One1 * A * B * C), Y = B-C, Z = X / Y, Z end,
amf2(N - 1, A, B, C, Fun).
ok1(0, A, _) ->
ok;
ok1(N, A, _) ->
IS = A == 1 orelse A == 2 orelse A == 3 orelse A == 4 orelse A == 5 orelse A == 6,
ok1(N - 1, A, IS).
ok2(0, A, _) ->
ok;
ok2(N, A, _) ->
IS = lists:member(A, [1, 2, 3, 4, 5, 6]),
ok2(N - 1, A, IS).
test2() ->
{Time, _} = timer:tc(?MODULE, compare, [100000000]),
io:format("Time : ~p~n", [Time]),
{Time2, _} = timer:tc(?MODULE, compare2, [100000000]),
io:format("Time2: ~p~n", [Time2]).
compare(0) ->
ok;
compare(N) when N =/= (N-1) orelse N =:= N ->
compare(N - 1).
compare2(0) ->
ok;
compare2(N) when N /= (N-1) orelse N == N ->
compare(N - 1).
timer(_, _) ->
I = atomics:add_get(persistent_term:get(cnt), 1, 1),
io:format("IMY******* ~p~n", [I]) ,
case I of
1000000 ->
io:format("end time ~p ~n", [erlang:system_time(millisecond)]);
_ ->
ignore
end,
ok.
test(N, Time) ->
io:format("start time1 ~p ~n", [erlang:system_time(millisecond)]),
persistent_term:put(cnt, atomics:new(1, [])),
gTimer:startWork(16),
doTest(N, Time).
doTest(0, Time) ->
io:format("start time2 ~p ~n", [erlang:system_time(millisecond)]),
gTimer:setTimer(rand:uniform(Time), {?MODULE, timer, []});
doTest(N, Time) ->
gTimer:setTimer(rand:uniform(Time), {?MODULE, timer, []}),
doTest(N - 1, Time).
timer(_) ->
%io:format("IMY******* ~p~n", [I]) ,
% case I of
% 1000000 ->
% io:format("end time ~p ~n", [erlang:system_time(millisecond)]);
% _ ->
% ignore
% end,
ok.
testBBB(Bin1) ->
Bin2 = term_to_binary(Bin1),
Bin = <<1:1, Bin2/binary>>,
io:format("IMY**********testBBB ~p size ~p ~p ~p ~n", [self(), bit_size(Bin), erts_internal:term_type(Bin), binaryAddr:getBinAddr(Bin2)]),
spawn(?MODULE, tt, [Bin]).
tt(B) ->
<<_A:1, Bin/binary>> = B,
io:format("IMY**********ttxxxxx ~p size ~p ~p ~p ~n", [self(), bit_size(B), erts_internal:term_type(B), binaryAddr:getBinAddr(Bin)]).

Loading…
Cancel
Save