(critical analysis of this assumption is welcome) ... using a hash makes random access faster as compared to arrays
Not so. Both hashes and arrays are classed as O(1) for access; but that 1 is much higher for hashes than for arrays:
@array = 1..100;; @hash{ 0 .. 99 } = @array;; cmpthese -1,{ a=>q[my$t=0; $t+=$_ for @array;], b=>q[my$t=0; $t+=$hash{$_} for keys %hash;] };; Rate b a b 35255/s -- -66% a 103177/s 193% --
Sparse matrix are only really useful when the ratio of zeros to non-zeros is greater than say 8:1 and the size is 100s of millions.
In reply to Re^2: Table shuffling challenge
by BrowserUk
in thread Table shuffling challenge
by glow_gene
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |