From a1a0821d286674b68b0234293e5e5a2ea0b977fa Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Wed, 20 Oct 2021 15:09:01 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/ping3.erl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/pong2.erl | 8 ++++---- test/pong3.erl | 17 +++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 test/ping3.erl create mode 100644 test/pong3.erl diff --git a/test/ping3.erl b/test/ping3.erl new file mode 100644 index 0000000..a6a6553 --- /dev/null +++ b/test/ping3.erl @@ -0,0 +1,46 @@ +-module(ping3). + +-compile([export_all, nowarn_export_all]). + +call(N) -> + {ok, Pid} = pong3:start(), + StartTime = erlang:system_time(nanosecond), + doCall(N, Pid, StartTime). + +doCall(0, Pid, StartTime) -> + EndTime = erlang:system_time(nanosecond), + exit(Pid, kill), + io:format("call3 over use time: ~p ns~n", [EndTime - StartTime]); +doCall(N, Pid, StartTime) -> + gen_apu:call(Pid, ping), + doCall(N - 1, Pid, StartTime). + +send(N) -> + {ok, Pid} = pong3:start(), + StartTime = erlang:system_time(nanosecond), + doSend(N, Pid, StartTime). + +doSend(0, Pid, StartTime) -> + % Ret = gen_apu:call(Pid, ping), + Ret = 1, + EndTime = erlang:system_time(nanosecond), + exit(Pid, kill), + io:format("send2 over use time: ~p ~p ns~n", [Ret, EndTime - StartTime]); +doSend(N, Pid, StartTime) -> + gen_apu:send(Pid, ping), + doSend(N - 1, Pid, StartTime). + +cast(N) -> + {ok, Pid} = pong3:start(), + StartTime = erlang:system_time(nanosecond), + doCast(N, Pid, StartTime). + +doCast(0, Pid, StartTime) -> + %Ret = gen_apu:call(Pid, ping), + Ret = 1, + EndTime = erlang:system_time(nanosecond), + exit(Pid, kill), + io:format("cast3 over use time: ~p ~p ns~n", [Ret, EndTime - StartTime]); +doCast(N, Pid, StartTime) -> + gen_apu:cast(Pid, ping2), + doCast(N - 1, Pid, StartTime). diff --git a/test/pong2.erl b/test/pong2.erl index 1e13b3c..a77788e 100644 --- a/test/pong2.erl +++ b/test/pong2.erl @@ -13,8 +13,8 @@ init(_Args) -> handleCall(ping, _State, _From) -> {reply, pong}. -handleCast(_Msg, State) -> - {noreply, State}. +handleCast(_Msg, _State) -> + kpS. -handleInfo(_Msg, State) -> - {noreply, State}. \ No newline at end of file +handleInfo(_Msg, _State) -> + kpS. \ No newline at end of file diff --git a/test/pong3.erl b/test/pong3.erl new file mode 100644 index 0000000..d598193 --- /dev/null +++ b/test/pong3.erl @@ -0,0 +1,17 @@ +-module(pong3). + +-behavior(gen_apu). + +-compile([export_all, nowarn_export_all]). + +start() -> + gen_apu:start(?MODULE, 0, []). + +init(_Args) -> + {ok, 0}. + +ping(_State, _From) -> + {reply, pong}. + +ping2(_State) -> + kpS. \ No newline at end of file