%%%-------------------------------------------------------------------
%%% File    : mtest.erl
%%% Author  : Goran Bage <goran.bage@mobilearts.se>
%%% Description : 
%%%
%%% Created : 18 Nov 2004 by Goran Bage <goran.bage@mobilearts.se>
%%%-------------------------------------------------------------------
-module(mtest).

-export([create/0,
	 fill/1,
	 test/0
        ]).

%%--------------------------------------------------------------------
%% Records
%%--------------------------------------------------------------------
-record(item, {key,
	       index,
	       data}).

%%====================================================================
%% External functions
%%====================================================================
create() ->
    mnesia:create_schema([node()]),
    mnesia:start(),
    {atomic, ok} = 
	mnesia:create_table(item,
			    [{attributes, record_info(fields, item)},
			     {index, [index]},
			     {type, set},
			     {disc_copies, [node()]}]).

test() ->
    mnesia:stop(),
    mnesia:start(),
    {Time, V} = timer:tc(mnesia, wait_for_tables, [[item], 10*60*1000]),
    N = length(mnesia:dirty_all_keys(item)),
    io:format("Size = ~w, Time = ~w, Res = ~p\n", [N, Time, V]).


fill(N) ->
    I = length(mnesia:dirty_all_keys(item)),
    fill(I, N),
    ok.
    

%%====================================================================
%% Internal functions
%%====================================================================

fill(I, N) when I < N ->
    mnesia:dirty_write(#item{key = I, data = any}),
    fill(I+1, N);
fill(_, _) ->
    ok.
