i have been working on a perl program to process large amounts of dna. It outputs exactly what i need however it takes much longer than i would like using NYTprof i have narrowed down the major problem areas to be the loop that adds my values together. would using inline::C to do the math make my program faster or should i accept the speed and move on? is there another way to improve the speed? here is my program and an input it would run as well as an executable with the default values entered already.
-
3did you try using `inline::C`? Did it work? – Mat Jul 05 '11 at 19:56
-
6I suggest you add the relevant extracts from your code inline here - the function / area NYTProf indicates as hot; and maybe even an extract of the NYTProf info for the area in question - this will help people more easily answer your question. – DaveR Jul 05 '11 at 19:59
-
It sounds rather hard to answer such a generic question without seeing at least some basic description of your program and/or data. – TLP Jul 05 '11 at 20:12
-
i am doing highly iterative tasks my program scans dna files for specific patters calculates vectors based on locations of said patterns and adds them. – Orion Jul 06 '11 at 14:13
-
codereview.stackexchange.com ? – AShelly Jul 06 '11 at 19:17
2 Answers
It's unlikely you'll get useful help here (this included). I can see various problems with your code, and none have to do with the choice of language.
use CPAN. If you're parsing genbank, then use some an appropriate module.
You're writing assembly in Perl, and neither Perl nor you are very good at that. It's near impossible to know what's going on when you don't pass parameters to subroutines, instead relying on globals all over the place. What do
@X1, @X2, @Y1, @Y2
mean?The following might be your problem:
until ($ender - $starter > $tlength) {
(line 153). According to your test case, these start by being 103, 1, and 200, and it's not clear when or if they change. Depending on what's in@te
, it might or might not ever get out of the loop; I just can't tell from your code.It would help if we knew, exactly, what are the parameters to
add
, the in-out invariants, and what it is returning.
That's all I got.

- 4,672
- 1
- 19
- 31
-
1well this helped enormously. i got it down to about 3 seconds from five minutes. thank you very much. – Orion Jul 07 '11 at 14:03
-
1
I second the recommendation of PDL made in a comment, if it's applicable. Or the use of a CPAN module tailored to your problem (again, if applicable).
I didn't see anything that looked unambiguously like "the loop that adds my values together" in that code; please, show just the code you are considering optimizing, ideally with just enough structure around it to actually run it.
So to answer your generic question generically, yes, Inline::C can be a useful tool for optimization if you are certain your performance problem is limited to what it actually can do for you. In using it, be aware that invoking your C code from Perl or vice versa is non-trivially expensive, so you have to have enough code translated to C to minimize the transitions.

- 96,171
- 6
- 121
- 214