Skip to content

Instantly share code, notes, and snippets.

@i110
Last active August 29, 2015 13:55
Show Gist options
  • Save i110/8712610 to your computer and use it in GitHub Desktop.
Save i110/8712610 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use Data::Validator;
my $start = [ gettimeofday ];
{
memory_usage();
foo();
memory_usage();
foo();
memory_usage();
}
my $end = [ gettimeofday ];
print 'elasped time: ' . tv_interval($start, $end);
sub foo {
for (1 .. 200) {
my $rule = Data::Validator->new(
name => 'Str',
age => 'Int',
)->with(qw(NoThrow AllowExtra));
}
}
sub memory_usage { system("ps uw -p $$") }
__END__
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23212 5.0 0.1 130648 4480 pts/7 S+ 01:29 0:00 perl -Ilib test2.pl
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23212 29.0 0.2 136064 9832 pts/7 S+ 01:29 0:00 perl -Ilib test2.pl
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23212 50.0 0.3 141080 14908 pts/7 S+ 01:29 0:00 perl -Ilib test2.pl
elasped time: 0.517146
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'state';
use Time::HiRes qw(gettimeofday tv_interval);
use Data::Validator;
my $start = [ gettimeofday ];
{
memory_usage();
foo();
memory_usage();
foo();
memory_usage();
}
my $end = [ gettimeofday ];
print 'elasped time: ' . tv_interval($start, $end);
sub foo {
for (1 .. 200) {
state $rule = Data::Validator->new(
name => 'Str',
age => 'Int',
)->with(qw(NoThrow AllowExtra));
}
}
sub memory_usage { system("ps uw -p $$") }
__END__
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23363 5.0 0.1 130792 4544 pts/7 S+ 01:30 0:00 perl -Ilib test2.pl
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23363 6.0 0.1 131056 4824 pts/7 S+ 01:30 0:00 perl -Ilib test2.pl
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ichito 23363 6.0 0.1 131056 4824 pts/7 S+ 01:30 0:00 perl -Ilib test2.pl
elasped time: 0.072832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment