Skip to content

Commit

Permalink
Merge pull request niner#15 from pypt/memleak-test-osx-bytes
Browse files Browse the repository at this point in the history
Multiply RSS usage on OS X to bytes
  • Loading branch information
niner authored Nov 9, 2016
2 parents 4ba2f53 + 37e38e4 commit a3700de
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions t/35dictunicodememleak.t
Original file line number Diff line number Diff line change
@@ -25,20 +25,25 @@ END
sub get_rss_memory {
my $pt = Proc::ProcessTable->new;
my %info = map { $_->pid => $_ } @{ $pt->table };
return $info{ $$ }->rss;
my $rss = $info{ $$ }->rss;
if ($^O eq 'darwin') {
# RSS is reported in kilobytes instead of bytes on OS X
$rss *= 1024;
}
return $rss;
}

my $iterations = 3_000_000;

my $rss_before_iterations = get_rss_memory();
# print STDERR "RSS (KB) before python_dict_with_unicode_key(): $rss_before_iterations\n";
# print STDERR "RSS before python_dict_with_unicode_key(): $rss_before_iterations\n";

my $dict;
for (my $x = 0; $x < $iterations; ++$x) {
$dict = python_dict_with_unicode_key();
}
my $rss_after_iterations = get_rss_memory();
# print STDERR "RSS (KB) after python_dict_with_unicode_key(): $rss_after_iterations\n";
# print STDERR "RSS after python_dict_with_unicode_key(): $rss_after_iterations\n";

ok( $rss_after_iterations - $rss_before_iterations < 100 * 1024, "RSS takes up less than 100 MB" );
ok( $rss_after_iterations - $rss_before_iterations < 100 * 1024 * 1024, "RSS takes up less than 100 MB" );
Test::Deep::cmp_deeply( $dict, { 'abcdefghijklmno' => 1, 'pqrstuvwxyz' => 2 } );

0 comments on commit a3700de

Please sign in to comment.