crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

test.cgi (1014B)


      1 #!/usr/bin/perl
      2 
      3 # Simple script for benchmarking purposes. Invoke as:
      4 #   http://whereever/test.cgi?bytes=XYZZY&usec=PLUGH
      5 # Will spam XYZZY bytes as payload, and delay for PLUGH microsecs.
      6 # The payload files are created in $tmpdir if they don't yet exist
      7 # so that CPU looping is avoided.
      8 
      9 use strict;
     10 use Time::HiRes qw(usleep);
     11 use CGI qw(:standard);
     12 
     13 my $tmpdir = '/tmp';
     14 
     15 # CGI Header
     16 print ("Content-Type: text/plain\r\n\r\n");
     17 
     18 # Delay for 'usec' microsecs.
     19 my $usec = param('usec') or 0;
     20 usleep($usec);
     21 
     22 # Check that we have a file for the payload. If not, create it.
     23 my $bytes = param('bytes');
     24 my $file  = "$tmpdir/test.cgi.$bytes";
     25 if (! -f $file) {
     26     open (my $of, ">$file") or die ("Cannot write $file: $!\n");
     27     for (my $i = 0; $i < $bytes; $i++) {
     28 	print $of ('X');
     29     }
     30     close ($of);
     31 }
     32 # Send the file to the browser.
     33 my $buf;
     34 open (my $if, $file) or die ("Cannot read $file: $!\n");
     35 while (sysread($if, $buf, 2048)) {
     36     print ($buf);
     37 }
     38 
     39 # All done. Return control to the web server.
     40 
     41