This commit is contained in:
Allen Xiang 2015-10-13 15:41:46 -05:00
parent 05b3261ca5
commit 727e7d4727
1 changed files with 12 additions and 13 deletions

View File

@ -1,16 +1,16 @@
%%----------------------------------------------------------------------------- %%-----------------------------------------------------------------------------
%% Copyright (c) 2012-2015, Feng Lee <feng@emqtt.io> %% Copyright (c) 2012-2015, Feng Lee <feng@emqtt.io>
%% %%
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights %% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is %% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions: %% furnished to do so, subject to the following conditions:
%% %%
%% The above copyright notice and this permission notice shall be included in all %% The above copyright notice and this permission notice shall be included in all
%% copies or substantial portions of the Software. %% copies or substantial portions of the Software.
%% %%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -68,10 +68,10 @@ sigle_level_match_test() ->
?assertNot( match(<<"/finance">>, <<"+">>) ). ?assertNot( match(<<"/finance">>, <<"+">>) ).
sys_match_test() -> sys_match_test() ->
?assert( match(<<"$SYS/borker/clients/testclient">>, <<"$SYS/#">>) ), ?assert( match(<<"$SYS/broker/clients/testclient">>, <<"$SYS/#">>) ),
?assert( match(<<"$SYS/borker">>, <<"$SYS/+">>) ), ?assert( match(<<"$SYS/broker">>, <<"$SYS/+">>) ),
?assertNot( match(<<"$SYS/borker">>, <<"+/+">>) ), ?assertNot( match(<<"$SYS/broker">>, <<"+/+">>) ),
?assertNot( match(<<"$SYS/borker">>, <<"#">>) ). ?assertNot( match(<<"$SYS/broker">>, <<"#">>) ).
'#_match_test'() -> '#_match_test'() ->
?assert( match(<<"a/b/c">>, <<"#">>) ), ?assert( match(<<"a/b/c">>, <<"#">>) ),
@ -84,7 +84,7 @@ match_perf_test() ->
Filter = <<"/abkc/19383/+/akakdkkdkak/#">>, Filter = <<"/abkc/19383/+/akakdkkdkak/#">>,
?assert( match(Name, Filter) ), ?assert( match(Name, Filter) ),
%?debugFmt("Match ~p with ~p", [Name, Filter]), %?debugFmt("Match ~p with ~p", [Name, Filter]),
{Time, _} = timer:tc(fun() -> {Time, _} = timer:tc(fun() ->
[match(Name, Filter) || _I <- lists:seq(1, ?N)] [match(Name, Filter) || _I <- lists:seq(1, ?N)]
end), end),
?debugFmt("Time for match: ~p(micro)", [Time/?N]), ?debugFmt("Time for match: ~p(micro)", [Time/?N]),
@ -92,11 +92,11 @@ match_perf_test() ->
triples_test() -> triples_test() ->
Triples = [{root, <<"a">>, <<"a">>}, {<<"a">>, <<"b">>, <<"a/b">>}], Triples = [{root, <<"a">>, <<"a">>}, {<<"a">>, <<"b">>, <<"a/b">>}],
?assertMatch(Triples, triples(<<"a/b">>) ). ?assertMatch(Triples, triples(<<"a/b">>) ).
triples_perf_test() -> triples_perf_test() ->
Topic = <<"/abkc/19383/192939/akakdkkdkak/xxxyyuya/akakak">>, Topic = <<"/abkc/19383/192939/akakdkkdkak/xxxyyuya/akakak">>,
{Time, _} = timer:tc(fun() -> {Time, _} = timer:tc(fun() ->
[triples(Topic) || _I <- lists:seq(1, ?N)] [triples(Topic) || _I <- lists:seq(1, ?N)]
end), end),
?debugFmt("Time for triples: ~p(micro)", [Time/?N]), ?debugFmt("Time for triples: ~p(micro)", [Time/?N]),
@ -109,11 +109,11 @@ type_test() ->
words_test() -> words_test() ->
?assertMatch(['', <<"abkc">>, <<"19383">>, '+', <<"akakdkkdkak">>, '#'], words(<<"/abkc/19383/+/akakdkkdkak/#">>)), ?assertMatch(['', <<"abkc">>, <<"19383">>, '+', <<"akakdkkdkak">>, '#'], words(<<"/abkc/19383/+/akakdkkdkak/#">>)),
{Time, _} = timer:tc(fun() -> {Time, _} = timer:tc(fun() ->
[words(<<"/abkc/19383/+/akakdkkdkak/#">>) || _I <- lists:seq(1, ?N)] [words(<<"/abkc/19383/+/akakdkkdkak/#">>) || _I <- lists:seq(1, ?N)]
end), end),
?debugFmt("Time for words: ~p(micro)", [Time/?N]), ?debugFmt("Time for words: ~p(micro)", [Time/?N]),
{Time2, _} = timer:tc(fun() -> {Time2, _} = timer:tc(fun() ->
[binary:split(<<"/abkc/19383/+/akakdkkdkak/#">>, <<"/">>, [global]) || _I <- lists:seq(1, ?N)] [binary:split(<<"/abkc/19383/+/akakdkkdkak/#">>, <<"/">>, [global]) || _I <- lists:seq(1, ?N)]
end), end),
?debugFmt("Time for binary:split: ~p(micro)", [Time2/?N]), ?debugFmt("Time for binary:split: ~p(micro)", [Time2/?N]),
@ -127,4 +127,3 @@ join_test() ->
?assertEqual(<<"ab/+/#">>, emqttd_topic:join(words(<<"ab/+/#">>))). ?assertEqual(<<"ab/+/#">>, emqttd_topic:join(words(<<"ab/+/#">>))).
-endif. -endif.