Thanks for all! It's working now, i just needed to replacing __END__ to __DATA__.
I need to write simple script, which calling functions from two modules (one of it contains perl code and another contains c code), measuares the time of each and if they calculation results are equals printing time differences of calulation.
Problem is that when i include module with c code and run main script perl says:
"readline() on unopened filehandle DATA at C:/other_perl/Strawberry/perl/site/lib/Inline.pm line 360.
Use of uninitialized value $data in substitution (s///) at C:/other_perl/Strawberry/perl/site/lib/In
line.pm line 360.
Use of uninitialized value $data in split at C:/other_perl/Strawberry/perl/site/lib/Inline.pm line 3
61.
No source code in DATA section for Inline 'C' section.
at optest.pl line 0.
INIT failed--call queue aborted.
One or more DATA sections were not processed by Inline."
Here is the main script:
use Time::HiRes qw(gettimeofday tv_interval);
use Test::More;
use perl_calc;
use c_calc;
$start_time_c = [ gettimeofday ];
$c_calc = c_calc::calc_pi();
$end_time_c = [ gettimeofday ];
$elapsed_c = tv_interval($start_time,$end_time);
$start_time_perl = [ gettimeofday ];
$perl_calc = perl_calc::calc_pi();
$end_time_perl = [ gettimeofday ];
$elapsed_perl = tv_interval($start_time,$end_time);
$differences = abs($elapsed_perl - $elapsed_c);
if(ok($c_calc == $perl_calc, "Pi number calc"))
{
print "C computation time = $elapsed_c\n";
print "Perl computation time = $elapsed_perl\n";
print "Differences = $differences\n";
}
done_testing;
Here is module with c code:
package c_calc;
use Inline 'C';
1;
__END__
__C__
double my_abs(double num)
{
return (num > 0)? num : -num;
}
double calc_pi()
{
double real_pi = 3.14159265358979;
double my_pi = 0;
double step_sign = 1;
unsigned long long i = 1;
while(my_abs(real_pi - my_pi) > 0.00000001)
{
my_pi += 4.0/i * step_sign;
step_sign *= -1;
i += 2;
}
return my_pi;
}
I read Inline::C-Cookbook, but i didn't find an answer there. So what i do wrong?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|