Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Dancer;
- use HTTP::Message::PSGI;
- use HTTP::Request;
- use Data::Dumper;
- use Memory::Usage;
- use bytes;
- set apphandler => 'PSGI';
- set serializer => 'JSON';
- post '/test' => sub {
- my $data = params('body');
- };
- my $app = dance;
- ################
- my $mu = Memory::Usage->new();
- my %data;
- $mu->record('before INC copy');
- $data{$_} = { %INC } for 0..1000;
- $mu->record('after INC copy');
- {
- my $content = to_json( \%data );
- warn "Content length: " . length( $content );
- my $req = HTTP::Request->new( POST => 'http://localhost/test', [ 'Content-Type' => 'application/json' ], $content );
- my $env = $req->to_psgi;
- $mu->record('before req');
- $app->( $env );
- $mu->record('after req');
- }
- {
- my $content = to_json( { data => \%data } );
- my $req = HTTP::Request->new( POST => 'http://localhost/test', [ 'Content-Type' => 'application/json' ], $content );
- my $env = $req->to_psgi;
- $mu->record('before req2');
- $app->( $env );
- $mu->record('after req2');
- }
- $mu->dump();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement