Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit ca9006e141d6b69dd7b1a5c29a150442227b68ec @meeusr committed Aug 8, 2012
Showing with 43 additions and 0 deletions.
  1. +21 −0 ordered_list.erl
  2. +22 −0 test_ets.erl
21 ordered_list.erl
@@ -0,0 +1,21 @@
+-module(ordered_list).
+-export([valid_entry_count/4,timediff/2]).
+
+timediff(Now,TS) ->
+ round(erlang:now_diff(Now,TS)/1000000).
+
+valid_entry_count(List,Now,Age,F) ->
+ valid_entry_count(List,Now,Age,F,0).
+
+valid_entry_count([],_Now,_Age,_F,Acc) ->
+ Acc;
+
+valid_entry_count([Head|Tail],Now,Age,F,Acc) ->
+ Diff = F(Now,Head),
+ io:format("valid_entry_count ~p\n",[Timediff]),
+ if
+ Diff < Age ->
+ valid_entry_count(Tail,Now,Age,F,Acc+1);
+ true -> Acc
+ end.
+
22 test_ets.erl
@@ -0,0 +1,22 @@
+-module(test_ets).
+-compile(export_all).
+
+perf_test(N,Length) ->
+ Table = ets:new( 'test_ets', [] ),
+ Data = lists:seq(1,Length),
+ Start = erlang:now(),
+ populate(Table,N,Data),
+ io:format("stop : ~p\n",[timer:now_diff(erlang:now(),Start)]),
+ lookup(Table),
+ ets:delete(Table).
+
+populate( _Table, 0, _Data) -> ok;
+
+populate( Table, N, Data ) ->
+ ets:insert( Table,{entry,N,Data}),
+ populate( Table,N-1,Data ).
+
+lookup( Table ) ->
+ [{entry,N,_List}] = ets:lookup( Table,entry ),
+ io:format("Lookup : ~p\n",[N]).
+

0 comments on commit ca9006e

Please sign in to comment.
Something went wrong with that request. Please try again.