in reply to Re^3: profiling XS routines
in thread profiling XS routines
And the result:use warnings; use Benchmark; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; /* These subs taken from * * "Extending and Embedding Perl" * * by Jenness and Cozens */ double sum_as_ref(AV * avref) { int i, len; double sum = 0; SV ** elem; len = av_len(avref) + 1; for(i = 0; i < len; i++) { elem = av_fetch(avref, i, 0); sum += (double)SvIV(*elem); } return sum; } double sum_as_list(SV * arg1, ...) { int i, len; double sum = 0; SV * elem; Inline_Stack_Vars; len = Inline_Stack_Items; for(i = 0; i < len; i++) { elem = Inline_Stack_Item(i); sum += (double)SvIV(elem); } return sum; } EOC our @x = (1 .. 2e6); our($list, $ref); timethese (1, { 'list' => '$list = sum_as_list(@x);', 'ref' => '$ref = sum_as_ref(\@x);', }); print "$list\n$ref\n";
Cheers, RobBenchmark: timing 1 iterations of list, ref... list: -1 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU) @ 7 +.09/s (n=1 ) (warning: too few iterations for a reliable count) ref: 0 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU) @ 7 +.09/s (n=1 ) (warning: too few iterations for a reliable count) 2000001000000 2000001000000
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: profiling XS routines
by BrowserUk (Patriarch) on Aug 30, 2009 at 02:58 UTC | |
|
Re^5: profiling XS routines
by BrowserUk (Patriarch) on Aug 30, 2009 at 04:40 UTC | |
by syphilis (Archbishop) on Aug 30, 2009 at 05:37 UTC |