Skip to content

Instantly share code, notes, and snippets.

@jef-sure
Created October 5, 2025 21:27
Show Gist options
  • Select an option

  • Save jef-sure/2d15ae175cc2e0cafb4a1f017c58df59 to your computer and use it in GitHub Desktop.

Select an option

Save jef-sure/2d15ae175cc2e0cafb4a1f017c58df59 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use Config;
use Inline C => Config => OPTIMIZE => " -O3 -march=native";
use Inline C => <<'END_OF_C_CODE';
SV* ret_c(SV* sv) {
return newSVnv(SvNV(sv) * 2.0);
}
END_OF_C_CODE
sub ret {
return $_[ 0 ] * 2;
}
sub blank {
$_[ 0 ] * 2;
}
my $subs = {
return => sub {
for(my $i=0 ; $i<=1_000 ; ++$i) {
my $res1 = ret( $i );
my $res2 = ret( $i );
my $res3 = ret( $i );
my $res4 = ret( $i );
my $res5 = ret( $i );
}
},
blank => sub {
for(my $i=0 ; $i<=1_000 ; ++$i) {
my $res1 = blank( $i );
my $res2 = blank( $i );
my $res3 = blank( $i );
my $res4 = blank( $i );
my $res5 = blank( $i );
}
},
ret_c => sub {
for(my $i=0 ; $i<=1_000 ; ++$i) {
my $res1 = ret_c( $i );
my $res2 = ret_c( $i );
my $res3 = ret_c( $i );
my $res4 = ret_c( $i );
my $res5 = ret_c( $i );
}
},
};
cmpthese( -50, $subs );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment