Skip to content

Instantly share code, notes, and snippets.

@wchristian
Last active February 13, 2017 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchristian/e431b1473b5f1cb45742fcdb42d31b4d to your computer and use it in GitHub Desktop.
Save wchristian/e431b1473b5f1cb45742fcdb42d31b4d to your computer and use it in GitHub Desktop.
=pod
d:\cpan\OpenGL>perl benchl.pl
true constant 0.118
xs constant 0.123
eval constant 0.238
func constant 0.121
glob constant 0.116
mod constant 0.117
scal constant 0.114
scalar 0.116
true constant 0.125
xs constant 0.125
eval constant 0.236
func constant 0.119
glob constant 0.122
mod constant 0.116
scal constant 0.119
scalar 0.119
=cut
use 5.010;
use strictures;
use Time::HiRes 'time';
use OpenGL::Modern qw' glEnable GL_MAX_3D_TEXTURE_SIZE';
use Const::Fast;
sub GL_MAX_3D_TEXTURE_SIZEp();
eval "
sub GL_MAX_3D_TEXTURE_SIZEp() { " . ( 1 + GL_MAX_3D_TEXTURE_SIZE ) . " };
1;
" or die $@;
sub GL_MAX_3D_TEXTURE_SIZEc() { 32885 }
BEGIN {
no strict 'refs';
my $num = 3 + GL_MAX_3D_TEXTURE_SIZE;
*{ __PACKAGE__ . "::GL_MAX_3D_TEXTURE_SIZEnostrict" } = sub () { $num };
}
BEGIN {
require constant;
constant->import( GL_MAX_3D_TEXTURE_SIZEimport => 4 + GL_MAX_3D_TEXTURE_SIZE );
}
const my $GL_MAX_3D_TEXTURE_SIZE => 32885;
my $GL_MAX_3D_TEXTURE_SIZEn = 32885;
my @counts = 1 .. 1_000_000;
my $c = GL_MAX_3D_TEXTURE_SIZE;
$c = GL_MAX_3D_TEXTURE_SIZEp;
$c = GL_MAX_3D_TEXTURE_SIZEc;
$c = GL_MAX_3D_TEXTURE_SIZEnostrict;
$c = GL_MAX_3D_TEXTURE_SIZEimport;
run();
sub run {
my $start = time;
glEnable 32885 for @counts;
$start = time;
glEnable 32885 for @counts;
say sprintf "true constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZE for @counts;
say sprintf "xs constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEp for @counts;
say sprintf "eval constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEc for @counts;
say sprintf "func constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEnostrict for @counts;
say sprintf "glob constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEimport for @counts;
say sprintf "mod constant %.3f", time - $start;
$start = time;
glEnable $GL_MAX_3D_TEXTURE_SIZE for @counts;
say sprintf "scal constant %.3f", time - $start;
$start = time;
glEnable $GL_MAX_3D_TEXTURE_SIZEn for @counts;
say sprintf "scalar %.3f", time - $start;
say "";
$start = time;
glEnable 32885 for @counts;
say sprintf "true constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZE for @counts;
say sprintf "xs constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEp for @counts;
say sprintf "eval constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEc for @counts;
say sprintf "func constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEnostrict for @counts;
say sprintf "glob constant %.3f", time - $start;
$start = time;
glEnable GL_MAX_3D_TEXTURE_SIZEimport for @counts;
say sprintf "mod constant %.3f", time - $start;
$start = time;
glEnable $GL_MAX_3D_TEXTURE_SIZE for @counts;
say sprintf "scal constant %.3f", time - $start;
$start = time;
glEnable $GL_MAX_3D_TEXTURE_SIZEn for @counts;
say sprintf "scalar %.3f", time - $start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment