http://qs1969.pair.com?node_id=1216694


in reply to Inline::C on Windows: how to improve performance of compiled code?

i hope for hints of what could be changed

The first hint that comes to mind is to perform the 1e8 function calls to foo() from inside C space, rather than from Perl space.
On top of the significant reduction in overhead, one then might also get to take advantage of C optimizations that are lost when the C function is called from Perl.
The following script aims at demonstrating the sort of savings you might get. I've changed foo() to be a little bit more than a no-op, in the hopes that it will remove the effect of clever C optimizations. (I don't know if I've been successful.):
use Time::HiRes qw(time); use Inline C => <<'EOC'; int foo(int x) {return x + 1;} int foo_bar(int x) { int i; for(i = 0; i < x; i++){ foo(i); } return x + i; } EOC $iterations = 10000000; # 1e7 $t = time; foo($_) for 1 .. $iterations; print "# ", time - $t, "\n"; $t = time; foo_bar($iterations); print "# ", time - $t, "\n"; # Outputs (on Windows): # 1.57560181617737 # 0.0026400089263916
On my Ubuntu (16.04) box, running perl-5.26, the same script outputs:
# 1.80176305770874 # 0.0337138175964355
Cheers,
Rob