Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Weighted frequency of characters in an array of strings

by Laurent_R (Canon)
on Jun 07, 2016 at 17:03 UTC ( [id://1165099]=note: print w/replies, xml ) Need Help??


in reply to Weighted frequency of characters in an array of strings

Hm, not entirely sure what will make things faster, but a few ideas:

You probably don't need to store your data into an array, and then go through the array, compute your counters right away when reading the data;

Use a hash of counters : $freq{$_} ++;

Don't do the division for each single letter: compute the counters, and only at the end, do the four needed divisions; or calculate 1/@data only once into a variable, and use the variable;

Using tr// is likely to be faster than a regex to count the letters. For example:

$c = "ACCCTGATTGC"; $d = $c =~ tr/A/A/; print $d; # prints 2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-29 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found