erlang 函数测试示例

main() ->
    List = [1,2,3,4,5,6,7,8,9,10],
    _Ret = [{a, Elem} || Elem <- List].


mhelp() ->
    List = [1,2,3,4,5,6,7,8,9,10],
    mhelp(List, []).
mhelp([], List) ->
    lists:reverse(List);
mhelp([E|Rest], List) ->
    mhelp(Rest, [{a, E}|List]).


test_main() ->
    statistics(wall_clock),
    for(1, 100000, fun(_) -> main() end),
    {_, Time} = statistics(wall_clock),
    ?print("test time = ~w", [Time]).


test_mhelp() ->
    statistics(wall_clock),
    for(1, 100000, fun(_) -> mhelp() end),
    {_, Time} = statistics(wall_clock),

    ?print("test time = ~w", [Time]).


或者timer:tc(t, test_main, []).

posted @ 2014-02-17 19:59  xiao913  阅读(158)  评论(0编辑  收藏  举报