Skip to content

Commit

Permalink
test helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed Mar 6, 2009
1 parent 9d6b1c8 commit 36815a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion erl/cherly.erl
Expand Up @@ -74,4 +74,5 @@ stop({cherly, P}) ->

load_driver() ->
Dir = filename:join([filename:dirname(code:which(cherly)), "..", "priv"]),
erl_ddll:load(Dir, "cherly_drv").
erl_ddll:load(Dir, "cherly_drv").

20 changes: 12 additions & 8 deletions etest/test_cherly.erl
Expand Up @@ -30,19 +30,23 @@ put_with_lru_eject_test() ->
?assertEqual(112, cherly:size(C)),
?assertEqual(7, cherly:items(C)),
cherly:stop(C).





succ([]) ->
[];

succ(Str) ->
succ_int(lists:reverse(Str), []).

succ_int([Char|Str], Acc) ->
if
Char >= $z -> succ_int(Str, [$a|Acc]);
true -> lists:reverse([Char+1|Acc] ++ Str)
end.
true -> lists:reverse(lists:reverse([Char+1|Acc]) ++ Str)
end.

fast_acc(_, Acc, 0) -> Acc;

fast_acc(Fun, Acc, N) ->
fast_acc(Fun, Fun(Acc), N-1).

time_to_epoch_float({Mega,Sec,Micro}) ->
Mega * 1000000 + Sec + Micro / 1000000.

4 comments on commit 36815a1

@etnt
Copy link

@etnt etnt commented on 36815a1 Mar 6, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, just curious why you don’t use ETS instead of the judy-arrays; what are the benefits? Cheers —Tobbe

@moonpolysoft
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much faster than using an ETS table.

@etnt
Copy link

@etnt etnt commented on 36815a1 Mar 7, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm…how can it be much faster? ETS is an in-memory hash table and as I understand it you’ll access the Judy-array lib (also in-memory) via an linked-in driver. Or perhaps I have misunderstod how you plan to use them? Do you have any measurments comparing the two?

@moonpolysoft
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talking strictly of the key/value get and put, smaller sized tables will be slightly faster in ets. After the table grows beyond a certain size, judy arrays will perform better. The more overriding concern, however, is making the key value lookup and insert work correctly and performantly with an LRU. The least algorithmically complex way I could find to do that is storing references to nodes in a doubly linked list for the LRU. And doing a scheme like that from the Erlang side instead of C would be challenging, to say the least. I’m on the train right now and must conserve battery, so I’ll post performance numbers later on today.

Please sign in to comment.