From d247aedb56b1cc0fd0824ff46909c014c65950e4 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sun, 16 May 2021 17:53:33 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/erlang/tryCatch性能说明.md | 77 +++++++++++++++++++++++++ src/testCase/TraceMod/utStrace5.erl | 11 +++- src/testCase/utTpfm.erl | 2 +- src/testCase/utTryCatchCase.erl | 28 +++++++-- 4 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 src/docs/erlang/tryCatch性能说明.md diff --git a/src/docs/erlang/tryCatch性能说明.md b/src/docs/erlang/tryCatch性能说明.md new file mode 100644 index 0000000..ec1f68c --- /dev/null +++ b/src/docs/erlang/tryCatch性能说明.md @@ -0,0 +1,77 @@ +# otp + otp24 + +## no catch + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testNoCatch, normal, true]). + SumTime: 630998000(ns) 0.630998(s) + AvgTime: 63099800.0(ns) 0.0631(s) + +## catch +###catch nomal + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testCatch, normal, true]). MaxTime: 74246000(ns) 0.074246(s) + SumTime: 725893000(ns) 0.725893(s) + AvgTime: 72589300.0(ns) 0.072589(s) + +###catch exit + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testCatch, exit, true]). + SumTime: 1264673000(ns) 1.264673(s) + AvgTime: 126467300.(ns) 0.126467(s) + +###catch error + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testCatch, error, true]). + SumTime: 1414449300(ns) 14.144493(s) + AvgTime: 1414449300(ns) 1.414449(s) + +###catch thorw + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testCatch, throw, true]). + SumTime: 1229429000(ns) 1.229429(s) + AvgTime: 122942900.(ns) 0.122943(s) + +## try catch(不匹配starace) +###catch nomal + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch, nomal, true]). + SumTime: 655993000(ns) 0.655993(s) + AvgTime: 65599300.0(ns) 0.065599(s) + +###catch exit + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch, exit, true]). + SumTime: 1479058000(ns) 1.479058(s) + AvgTime: 147905800.(ns) 0.147906(s) + + +###catch error + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch, error, true]). + SumTime: 1290286000(ns) 1.290286(s) + AvgTime: 129028600.(ns) 0.129029(s) + +###catch throw + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch, throw, true]). + SumTime: 1385688000(ns) 1.385688(s) + AvgTime: 138568800.(ns) 0.138569(s) + + +## try catch(匹配starace) +###catch nomal + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch2, normal, true]). + SumTime: 663833000(ns) 0.663833(s) + AvgTime: 66383300.0(ns) 0.066383(s) + + + +###catch exit + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch2, exit, true]). + SumTime: 1385211400(ns) 13.852114(s) + AvgTime: 1385211400(ns) 1.385211(s) + +###catch error + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch2, error, true]). + SumTime: 1370759800(ns) 13.707598(s) + AvgTime: 1370759800(ns) 1.37076(s) + +###catch throw + utTc:ts(10, utTryCatchCase, loopTest, [1000000, testTryCatch2, throw, true]). + SumTime: 1386053800(ns) 13.860538(s) + AvgTime: 1386053800(ns) 1.386054(s) + + + diff --git a/src/testCase/TraceMod/utStrace5.erl b/src/testCase/TraceMod/utStrace5.erl index 2d2ac94..588f163 100644 --- a/src/testCase/TraceMod/utStrace5.erl +++ b/src/testCase/TraceMod/utStrace5.erl @@ -3,7 +3,12 @@ -export([test/1]). test(Data) -> - timer:sleep(30), - utStrace1:test(Data), - {ok, Data}. + %% 这段代码用来测试 try catch 堆栈 + utTryCatchCase:makeException2(Data). + + %% 这段代码用来测试非尾递归堆栈大小模拟测试 + %% timer:sleep(30), + %% utStrace1:test(Data), + %% {ok, Data}. + diff --git a/src/testCase/utTpfm.erl b/src/testCase/utTpfm.erl index 77d8a4b..87a4387 100644 --- a/src/testCase/utTpfm.erl +++ b/src/testCase/utTpfm.erl @@ -586,7 +586,7 @@ etsInsert(0, Tab) -> ets:insert(Tab, {etsT, 50000, 500, 5001}), ok; etsInsert(N, Tab) -> - ets:insert(Tab, {test, N, N, N + 1}), + ets:insert(Tab, {etsT, N, N, N + 1}), etsInsert(N - 1, Tab). -include_lib("stdlib/include/ms_transform.hrl"). diff --git a/src/testCase/utTryCatchCase.erl b/src/testCase/utTryCatchCase.erl index 48b6cbc..ada0e9d 100644 --- a/src/testCase/utTryCatchCase.erl +++ b/src/testCase/utTryCatchCase.erl @@ -1,7 +1,16 @@ -module(utTryCatchCase). -compile([export_all, nowarn_unused_function, nowarn_unused_vars, nowarn_export_all]). --export([loopTest/4, testTryCatch/1, testTryCatch/2, testCatch/1, testCatch/2, testTryCatch2/1, testTryCatch2/2]). + +-export([ + loopTest/4 + , testTryCatch/1 + , testTryCatch/2 + , testCatch/1 + , testCatch/2 + , testTryCatch2/1 + , testTryCatch2/2 +]). t1() -> Pid = spawn(fun() -> do_t1(1) end), @@ -26,7 +35,7 @@ do_t1(N) -> erlang:garbage_collect(), Result = erlang:process_info(self(), [memory, garbage_collection]), io:format("IMY************************* ~p~n ~w ~n", [N, Result]); - %io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p~n backtrace:~p~n~n", [N, erlang:process_display(self(), backtrace)]); + %io:format("IMY&&&&&&&&&&&&&&&&&&&&&&&&& ~p~n backtrace:~p~n~n", [N, erlang:process_display(self(), backtrace)]); _ -> ignore end, @@ -217,7 +226,14 @@ loopTest(Times, Fun, Type, IsLoop) -> ?MODULE:Fun(Type, IsLoop), loopTest(Times - 1, Fun, Type, IsLoop). -testTryCatch(Type) -> testTryCatch(Type, false). +testNoCatch(Type) -> + testNoCatch(Type, false). + +testNoCatch(Type, _TestLoop) -> + makeException(Type). + +testTryCatch(Type) -> + testTryCatch(Type, false). testTryCatch(Type, TestLoop) -> try @@ -230,7 +246,8 @@ testTryCatch(Type, TestLoop) -> end end. -testTryCatch2(Type) -> testTryCatch(Type, false). +testTryCatch2(Type) -> + testTryCatch2(Type, false). testTryCatch2(Type, TestLoop) -> try @@ -264,6 +281,9 @@ testCatch(Type, TestLoop) -> makeException(Type) -> + utStrace1:test(Type). + +makeException2(Type) -> case Type of throw -> erlang:throw(test); error -> erlang:error(test);