Browse Source

test ETS rows count

221V 3 years ago
parent
commit
f240798b99
2 changed files with 33 additions and 4 deletions
  1. 3 0
      apps/myapp/src/myapp_events2.erl
  2. 30 4
      apps/myapp/src/test.erl

+ 3 - 0
apps/myapp/src/myapp_events2.erl

@@ -6,6 +6,7 @@
 
 -export([add_task/4, delete_task/2]).
 -export([add_task_b/4, delete_task_b/2]).
+-export([check_ets_count/0]).
 
 
 -define(IS_STRING(S), (is_list(S) andalso S /= [] andalso is_integer(hd(S)))).
@@ -124,3 +125,5 @@ code_change(_OldVsn, State, _Extra) ->
   {ok, State}.
 
 
+check_ets_count() -> ets:info(events_table, 'size').
+

+ 30 - 4
apps/myapp/src/test.erl

@@ -54,11 +54,24 @@ testn(T) -> % T -- умовно секунди - кількість циклів
   end),
   
   spawn(fun() ->
+    io:format("count before: ~p~n", [myapp_events2:check_ets_count()]),
     T1 = erlang:system_time(millisecond),
     testn_h(T rem 2 =:= 0),
     T2 = erlang:system_time(millisecond),
-    io:format("~p~n",[T2 - T1]),
-    ok
+    io:format("count after: ~p~n", [myapp_events2:check_ets_count()]),
+    io:format("~p milliseconds~n==========================================~n",[T2 - T1]),
+    
+    case T of
+      1 ->
+        % check count 5 sec after
+        spawn(fun() ->
+          timer:sleep(5000),
+          io:format("result count: ~p~n", [myapp_events2:check_ets_count()])
+        end),
+        ok;
+      _ -> ok
+    end
+    
   end),
   ok.
 
@@ -103,11 +116,24 @@ testn_b(T) -> % T -- умовно секунди - кількість циклі
   end),
   
   spawn(fun() ->
+    io:format("count before: ~p~n", [myapp_events2:check_ets_count()]),
     T1 = erlang:system_time(millisecond),
     testn_h2(T rem 2 =:= 0),
     T2 = erlang:system_time(millisecond),
-    io:format("~p~n",[T2 - T1]),
-    ok
+    io:format("count after: ~p~n", [myapp_events2:check_ets_count()]),
+    io:format("~p milliseconds~n==========================================~n",[T2 - T1]),
+    
+    case T of
+      1 ->
+        % check count 5 sec after
+        spawn(fun() ->
+          timer:sleep(5000),
+          io:format("result count: ~p~n", [myapp_events2:check_ets_count()])
+        end),
+        ok;
+      _ -> ok
+    end
+    
   end),
   ok.