Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael G. Schwern schwern

View GitHub Profile
@schwern
schwern / builtin_vs_ms_runtime
Created Mar 26, 2014
5.20 signatures vs Method::Signatures, runtime benchmark
View builtin_vs_ms_runtime
#!/usr/bin/perl
use v5.10;
use strict;
use warnings;
use Benchmark qw(cmpthese);
{
package MS;
@schwern
schwern / builtin_vs_ms_compile
Last active Aug 29, 2015
5.20 signatures vs Method::Signatures - compile time benchmark at realistic scales
View builtin_vs_ms_compile
#!/usr/bin/perl
use v5.19;
use strict;
use warnings;
# This isn't strictly necessary, I just want to use them.
use feature 'signatures';
no warnings 'experimental::signatures';
@schwern
schwern / gist:9943058
Created Apr 2, 2014
The fibnonacci sequence implemented as a method on an immutable integer class, with purely per object caching, for demonstration purposes.
View gist:9943058
#!/usr/bin/perl
use perl5i::2;
# A full on Integer class.
{
package _Integer;
use perl5i::2;
use Method::Signatures;
@schwern
schwern / gist:9942847
Created Apr 2, 2014
The fibnonacci sequence implemented as a method on an integer class, with caching, for demonstration purposes.
View gist:9942847
#!/usr/bin/perl
use perl5i::2;
# A full on Integer class.
{
package Integer;
use perl5i::2;
use Method::Signatures;
@schwern
schwern / gist:9942770
Last active Aug 29, 2015
The fibnonacci sequence implemented as a method on an autoboxed integer/scalar class, with caching, for demonstration purposes.
View gist:9942770
#!/usr/bin/perl
# This turns on function signatures and autoboxing
# amongst a lot of other things.
use perl5i::2;
# This class adds methods callable on all scalar variables.
{
package SCALAR;
use perl5i::2;
View gist:9962275
$ ps auwx | head -1
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
$ ps auwx | grep perl
schwern 3574 0.0 0.0 2442000 628 s000 S+ 10:50AM 0:00.00 grep perl
schwern 3567 0.0 1.0 2507496 80168 s001 S 10:50AM 0:00.13 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; sleep 9999
schwern 3558 0.0 1.0 2517736 80244 s001 S 10:50AM 0:00.56 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; print {$fh} $_ for @list; sleep 9999
schwern 3557 0.0 1.0 2525928 80232 s001 S 10:50AM 0:00.45 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; print $fh @list; sleep 9999
View gist:9964160
#!/usr/bin/perl
use Devel::Peek;
sub foo {
print Dump( \@_ );
}
my @list = qw(1 2 3);
foo(@list);
View gist:9964225
$ ps auwx | head -1
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
$ ps auwx | grep perl
schwern 4311 0.0 0.0 2442000 620 s000 S+ 3:30PM 0:00.00 grep perl
schwern 4309 0.1 1.0 2515688 80204 s001 S 3:30PM 0:00.14 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; sub foo {} foo(); sleep 9999
schwern 4301 0.0 1.0 2525552 88052 s001 S 3:30PM 0:00.14 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; sub foo {} foo(@list); sleep 9999
schwern 4304 0.0 1.0 2525928 80232 s001 S 3:30PM 0:00.47 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; sub foo {} print {$fh} @list; sleep 9999
schwern 4336 0.0 1.0 2517736 80236 s001 S 3:35PM 0:00.47 perl -wle my @list = (1..1_000_000); open my $fh, ">>", "/dev/null"; sub foo {} print {$fh} @list, "foo"; sleep 9999
View gist:9959154
#!/usr/bin/perl
use v5.10;
use strict;
use warnings;
use Benchmark qw(cmpthese);
my @list = (1..1_000_000);
local $, = '';
@schwern
schwern / gist:10081851
Created Apr 8, 2014
Demonstrate Moose breaking App::Cmd commands
View gist:10081851
#!/usr/bin/perl
{
package App::Cmd::Bug;
use App::Cmd::Setup -app;
BEGIN { $INC{"App/Cmd/Bug.pm"} = 1; }
}
{
package App::Cmd::Bug::Command::foo;