#!/usr/bin/perl
# -*- Mode: perl -*-

use SVN::Client;
use Time::HiRes qw(gettimeofday tv_interval);

use Getopt::Long qw(:config bundling);
use Pod::Usage;

use strict;

$| = 1; # force autoflush

#==========================================================================
MAIN : {
  my ($program, $HOME, $USER, $help, $man, $verbose, $numIter, $baseURL);

  # Trap initial state 
  ($program = $0)   =~ s%.*/%%;   # What are we running?
  $HOME       = $ENV{'HOME'};     # Where are we runing?
  ($USER = getlogin) ||           # Who are we running under?
    ($USER = $ENV{'USER'}) ||
      (($USER) = getpwuid($<));

  if( !GetOptions(
		  'help|h|?'       => \$help,
		  'man|m'          => \$man,
          'numIter=i'      => \$numIter,
          'baseURL=s'      => \$baseURL,
		  'verbose|v'      => \$verbose,
		 ) ) {
    exit 1;
  }

  pod2usage (-exitstatus => 0, -verbose=>1) if (defined $help);
  pod2usage (-exitstatus => 0, -verbose=>2) if (defined $man);

  my $ctx = new SVN::Client ( auth => [SVN::Client::get_simple_provider(),
                      SVN::Client::get_simple_prompt_provider (\&cachedSimpleProvider,2),
                      SVN::Client::get_username_provider(),
                      SVN::Client::get_ssl_server_trust_file_provider(),
                      SVN::Client::get_ssl_server_trust_prompt_provider
                      (\&cachedSSLServerTrustProvider)]);


  my $srcURL = "$baseURL/benchmark/trunk";
  my $start = [gettimeofday ()];
  for (my $i = 0; $i < $numIter; $i++) {
     $ctx->ls ($srcURL, 'HEAD', 0);
  }

  
  my $total = tv_interval ($start);
  my $individ = $total / $numIter;
  print "Total time: " . $total . "\n";
  print "Time per ls: " . $individ . "\n";
}





