Advertisement
Guest User

Dancer memory test case

a guest
Oct 16th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.05 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Dancer;
  4. use HTTP::Message::PSGI;
  5. use HTTP::Request;
  6. use Data::Dumper;
  7. use Memory::Usage;
  8. use bytes;
  9.  
  10.  
  11. set apphandler => 'PSGI';
  12. set serializer => 'JSON';
  13.  
  14. post '/test' => sub {
  15.     my $data = params('body');
  16. };
  17.  
  18. my $app = dance;
  19.  
  20. ################
  21.  
  22. my $mu = Memory::Usage->new();
  23. my %data;
  24. $mu->record('before INC copy');
  25. $data{$_} = { %INC } for 0..1000;
  26. $mu->record('after INC copy');
  27.  
  28. {
  29.     my $content = to_json( \%data );
  30.     warn "Content length: " . length( $content );
  31.     my $req = HTTP::Request->new( POST => 'http://localhost/test', [ 'Content-Type' => 'application/json' ], $content );
  32.     my $env = $req->to_psgi;
  33.  
  34.     $mu->record('before req');
  35.     $app->( $env );
  36.     $mu->record('after req');
  37. }
  38.  
  39. {
  40.     my $content = to_json( { data => \%data } );
  41.     my $req = HTTP::Request->new( POST => 'http://localhost/test', [ 'Content-Type' => 'application/json' ], $content );
  42.     my $env = $req->to_psgi;
  43.  
  44.     $mu->record('before req2');
  45.     $app->( $env );
  46.     $mu->record('after req2');
  47. }
  48.  
  49. $mu->dump();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement