Skip to content

Instantly share code, notes, and snippets.

View schwern's full-sized avatar

Michael G. Schwern schwern

View GitHub Profile
@schwern
schwern / builtin_vs_ms_compile
Last active August 29, 2015 13:57
5.20 signatures vs Method::Signatures - compile time benchmark at realistic scales
#!/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 / builtin_vs_ms_runtime
Created March 26, 2014 19:39
5.20 signatures vs Method::Signatures, runtime benchmark
#!/usr/bin/perl
use v5.10;
use strict;
use warnings;
use Benchmark qw(cmpthese);
{
package MS;
@schwern
schwern / gist:9942770
Last active August 29, 2015 13:58
The fibnonacci sequence implemented as a method on an autoboxed integer/scalar class, with caching, for demonstration purposes.
#!/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;
@schwern
schwern / gist:9942847
Created April 2, 2014 20:49
The fibnonacci sequence implemented as a method on an integer class, with caching, for demonstration purposes.
#!/usr/bin/perl
use perl5i::2;
# A full on Integer class.
{
package Integer;
use perl5i::2;
use Method::Signatures;
@schwern
schwern / gist:9943058
Created April 2, 2014 20:59
The fibnonacci sequence implemented as a method on an immutable integer class, with purely per object caching, for demonstration purposes.
#!/usr/bin/perl
use perl5i::2;
# A full on Integer class.
{
package _Integer;
use perl5i::2;
use Method::Signatures;
#!/usr/bin/perl
use v5.10;
use strict;
use warnings;
use Benchmark qw(cmpthese);
my @list = (1..1_000_000);
local $, = '';
$ 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
#!/usr/bin/perl
use Devel::Peek;
sub foo {
print Dump( \@_ );
}
my @list = qw(1 2 3);
foo(@list);
$ 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
@schwern
schwern / gist:10081851
Created April 8, 2014 01:48
Demonstrate Moose breaking App::Cmd commands
#!/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;