performance - Fastest type to use for comparing hashes in matlab -
i have table in matlab columns representing 128 bit hashes.
i match rows, 1 or more rows, based on these hashes.
currently, hashes represented hexadecimal strings, , compared strcmp(). still, takes many seconds process table.
what fastest way compare 2 hashes in matlab?
i have tried turning them categorical variables, slower. matlab far know not have 128 bit numerical type. nominal , ordinal types deprecated.
are there others work?
the code below analogous doing:
nodetype = { 'type1'; 'type2'; 'type1'; 'type2' }; hash = {'d285e87940fb9383ec5e983041f8d7a6'; 'd285e87940fb9383ec5e983041f8d7a6'; 'ec9add3cf0f67f443d5820708adc0485'; '5dbdfa232b5b61c8b1e8c698a64e1cc9' }; entries = table(categorical(nodetype),hash,'variablenames',{'type','hash'}); %nodes match. filter type or other way rows don't match %themselves. = entries(entries.type=='type1',:); b = entries(entries.type=='type2',:); %pick node/row hash find counterparts of row_to_match_in_a = a(1,:); matching_rows_in_b = b(strcmp(b.hash,row_to_match_in_a.hash),:); % stuff matching rows... disp(matching_rows_in_b); the hash strings faithful representations of using, not read or stored strings in original source. converted purpose because fastest way comparison.
optimization nice, if need it. try out , measure performance gain relevant test cases.
some suggestions:
- sorted arrays easier/faster search
matlab's default numbers
double, but can construct integers. why not use 2uint64's instead of 128bit column? first search upper 64bit, lower; or better: useismemberrowoption , put hashes in rows:a = uint64([0 0; 0 1; 1 0; 1 1; 2 0; 2 1]); srch = uint64([1 1; 0 1]); [ismatch, loc] = ismember(srch, a, 'rows') > loc = 4 2look compare functions use (eg
edit ismember) , strip out unnecessary operations (egsort) , safety checks know in advance won't pose problem. like solution does. or if intend call search function multiple times, sort in advance , skip check/sort in search function later on.
Comments
Post a Comment