diff --git a/src/dataType/utRiro.erl b/src/dataType/utFifo.erl similarity index 75% rename from src/dataType/utRiro.erl rename to src/dataType/utFifo.erl index 2d7bea9..94431b3 100644 --- a/src/dataType/utRiro.erl +++ b/src/dataType/utFifo.erl @@ -1,7 +1,4 @@ --module(utRiro). - --compile(inline). --compile({inline_size, 128}). +-module(utFifo). -export([ new/1 @@ -21,27 +18,27 @@ new(Name) -> name_used end. --spec del(Name :: atom()) -> ok | error_lifo. +-spec del(Name :: atom()) -> ok. del(Name) -> ets:delete(Name). --spec in(Name :: atom(), Value :: term()) -> true | false | error_lifo. +-spec in(Name :: atom(), Value :: term()) -> true. in(Name, Value) -> - ets:insert_new(Name, {Value}). + ets:insert(Name, {erlang:unique_integer(), Value}). -spec out(Name :: atom()) -> empty | Value :: term(). out(Name) -> do_out(Name). do_out(Name) -> - case ets:last(Name) of + case ets:first(Name) of '$end_of_table' -> empty; Key -> case ets:take(Name, Key) of [] -> do_out(Name); - [{Value}] -> + [{_, Value}] -> Value end end. diff --git a/src/dataType/utLifo.erl b/src/dataType/utLifo.erl index 2a99b48..87d9c7b 100644 --- a/src/dataType/utLifo.erl +++ b/src/dataType/utLifo.erl @@ -1,5 +1,8 @@ -module(utLifo). +-compile(inline). +-compile({inline_size, 128}). + -export([ new/1 , del/1 @@ -11,89 +14,43 @@ -spec new(Name :: atom()) -> ok | name_used. new(Name) -> - case persistent_term:get(Name, undefined) of + case ets:info(Name, id) of undefined -> - ARef = atomics:new(1, [{signed, false}]), - ets:new(Name, [set, named_table, {write_concurrency, true}]), - persistent_term:put(Name, ARef), - ok; + ets:new(Name, [ordered_set, named_table, {write_concurrency, true}]); _ -> - case ets:info(Name, id) of - undefined -> - ets:new(Name, [set, named_table, {write_concurrency, true}]); - _ -> - name_used - end + name_used end. -spec del(Name :: atom()) -> ok | error_lifo. del(Name) -> - case persistent_term:get(Name, undefined) of - undefined -> - error_lifo; - _ -> - persistent_term:erase(Name), - ets:delete(Name), - ok - end. + ets:delete(Name). --spec in(Name :: atom(), Value :: term()) -> true | false | error_lifo. +-spec in(Name :: atom(), Value :: term()) -> true. in(Name, Value) -> - case persistent_term:get(Name, undefined) of - undefined -> - error_lifo; - ARef -> - in(ARef, Name, Value) - end. - -in(ARef, Name, Value) -> - Index = atomics:add_get(ARef, 1, 1), - case ets:insert_new(Name, {Index, Value}) of - true -> - true; - _ -> - in(ARef, Name, Value) - end. + ets:insert(Name, {erlang:unique_integer(), Value}). --spec out(Name :: atom()) -> error_lifo | empty | Value :: term(). +-spec out(Name :: atom()) -> empty | Value :: term(). out(Name) -> - case persistent_term:get(Name, undefined) of - undefined -> - error_lifo; - ARef -> - out(ARef, Name) - end. - -out(ARef, Name) -> - Index = atomics:sub_get(ARef, 1, 1), - case ets:take(Name, Index + 1) of - [] -> - case ets:info(Name, size) of - 0 -> - empty; - _ -> - out(ARef, Name) - end; - [{_, Value}] -> - Value + do_out(Name). + +do_out(Name) -> + case ets:last(Name) of + '$end_of_table' -> + empty; + Key -> + case ets:take(Name, Key) of + [] -> + do_out(Name); + [{_, Value}] -> + Value + end end. --spec clear(Name :: atom()) -> error_lifo | ok. +-spec clear(Name :: atom()) -> ok. clear(Name) -> - case persistent_term:get(Name, undefined) of - undefined -> - error_lifo; - _ -> - ets:delete_all_objects(Name), - ok - end. + ets:delete_all_objects(Name). --spec size(Name :: atom()) -> Size :: integer() | error_lifo. +-spec size(Name :: atom()) -> Size :: integer() | undefined. size(Name) -> - case ets:info(Name, size) of - undefined -> - error_lifo; - Size -> - Size - end. + ets:info(Name, size). diff --git a/src/measure/DsTestSimple/utSTestDs.erl b/src/measure/DsTestSimple/utSTestDs.erl index cb6a9cf..3a5c485 100644 --- a/src/measure/DsTestSimple/utSTestDs.erl +++ b/src/measure/DsTestSimple/utSTestDs.erl @@ -11,7 +11,7 @@ %-define(V_NUM, [8, 16, 32, 64, 128, 256, 516, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 524288, 1048576]). -define(V_NUM, [8, 16, 32, 64, 128, 256, 516, 1024, 2048, 4096]). --define(DsList, [utSPdDs, utSTupleDs, utSListsDs, utSMapsDs, utSQueueDs, utSUtRiroDs, utSUtLifoDs, utSEtsSetDs, utSEtsOrdDs, utSArrayDs, utSDictDs, utSGb_treesDs, utSSetsDs, utSGb_setsDs, utSOrddictDs, utSOrdsetsDs]). +-define(DsList, [utSPdDs, utSTupleDs, utSListsDs, utSMapsDs, utSQueueDs, utSUtFifoDs, utSUtLifoDs, utSEtsSetDs, utSEtsOrdDs, utSArrayDs, utSDictDs, utSGb_treesDs, utSSetsDs, utSGb_setsDs, utSOrddictDs, utSOrdsetsDs]). %-define(DsList, [utSPdDs, utSTupleDs, utSMapsDs, utSArrayDs, utSEtsSetDs, utSSetsDs]). -define(Cnt, 12). diff --git a/src/measure/DsTestSimple/utSUtRiroDs.erl b/src/measure/DsTestSimple/utSUtFifoDs.erl similarity index 79% rename from src/measure/DsTestSimple/utSUtRiroDs.erl rename to src/measure/DsTestSimple/utSUtFifoDs.erl index a5f7e2c..2682eb8 100644 --- a/src/measure/DsTestSimple/utSUtRiroDs.erl +++ b/src/measure/DsTestSimple/utSUtFifoDs.erl @@ -1,4 +1,4 @@ --module(utSUtRiroDs). +-module(utSUtFifoDs). -compile([nowarn_unused_function, nowarn_unused_vars, nowarn_export_all]). -export([start/2]). @@ -16,13 +16,13 @@ start(Num, Pid) -> Time5 = erlang:monotonic_time(), delete(Num, NewDsF), Time6 = erlang:monotonic_time(), - erlang:send(Pid, {over, self(), Time2 - Time1, Time3 - Time2, not_support, not_support, not_support, ets:info(test_riro, memory)}), + erlang:send(Pid, {over, self(), Time2 - Time1, Time3 - Time2, not_support, not_support, not_support, ets:info(test_fifo, memory)}), exit(normal). init(_Num) -> - case utRiro:new(test_riro) of + case utFifo:new(test_fifo) of name_used -> - utRiro:clear(test_riro); + utFifo:clear(test_fifo); _ -> ok end. @@ -30,13 +30,13 @@ init(_Num) -> insert(0, Ds) -> Ds; insert(Num, _Ds) -> - NewDs = utRiro:in(test_riro, Num), + NewDs = utFifo:in(test_fifo, Num), insert(Num - 1, NewDs). read(0, Ds) -> Ds; read(Num, Ds) -> - Value = utRiro:out(test_riro), + Value = utFifo:out(test_fifo), read(Num - 1, Ds). update(Num, Ds) -> diff --git a/src/measure/utTc.erl b/src/measure/utTc.erl index 6f9e8cc..c28b358 100644 --- a/src/measure/utTc.erl +++ b/src/measure/utTc.erl @@ -152,7 +152,7 @@ tm(ProcCnt, LoopTime, M, F, A) -> io:format("PMinTime: ~10s(ns) ~10s(s)~n", [integer_to_binary(Min), float_to_binary(Min / 1000000000, [{decimals, 6}, compact])]), io:format("PSumTime: ~10s(ns) ~10s(s)~n", [integer_to_binary(Sum), float_to_binary(Sum / 1000000000, [{decimals, 6}, compact])]), io:format("PAvgTime: ~10s(ns) ~10s(s)~n", [float_to_binary(Aver, [{decimals, 6}, compact]), float_to_binary(Aver / 1000000000, [{decimals, 6}, compact])]), - io:format("FAvgTime: ~10s(ns) ~10s(s)~n", [float_to_binary(Aver, [{decimals, 6}, compact]), float_to_binary(Aver / LoopTime / 1000000000, [{decimals, 6}, compact])]), + io:format("FAvgTime: ~10s(ns) ~10s(s)~n", [float_to_binary(Aver / LoopTime, [{decimals, 6}, compact]), float_to_binary(Aver / LoopTime / 1000000000, [{decimals, 6}, compact])]), io:format("PGrar : ~10s(cn) ~10s(~s)~n", [integer_to_binary(Greater), float_to_binary(Greater / ProcCnt, [{decimals, 2}]), <<"%">>]), io:format("PLess : ~10s(cn) ~10s(~s)~n", [integer_to_binary(Less), float_to_binary(Less / ProcCnt, [{decimals, 2}]), <<"%">>]), io:format("=====================~n").