#!perl -w

use strict;

BEGIN { $Date::Calc::XS_DISABLE = 1; }

use Benchmark qw(:hireswallclock);

use Carp::Clan qw(^Date::);

require Date::Calc::Object; Date::Calc::Object->import(':all');
require Date::Calendar::Profiles;
require Date::Calendar::Year;
require Date::Calendar;

my $name = $0;
$name =~ s!^.*[/\\:]!!;
$name =~ s!\.+[^./\\:]*$!!;

my $loop = 10000;

print "Running under " . ($Date::Calc::XS_OK ? "Date::Calc::XS version " . Date::Calc::XS::Version() : "Date::Calc::PP version " . Date::Calc::PP::Version() ) . "\n";

timethis($loop, \&test_all);

{
    delete $INC{'Date/Calc.pm'};
    delete $INC{'Date/Calc/PP.pm'};
    delete $INC{'Date/Calc/Object.pm'};
    delete $INC{'Date/Calendar.pm'};
    delete $INC{'Date/Calendar/Year.pm'};
    delete $INC{'Date/Calendar/Profiles.pm'};
    undef $Date::Calc::XS_DISABLE;
    undef $Date::Calc::XS_OK;
    local($^W) = 0;
    require Date::Calc::Object; Date::Calc::Object->import(':all');
    require Date::Calendar::Profiles;
    require Date::Calendar::Year;
    require Date::Calendar;
}

print "Running under " . ($Date::Calc::XS_OK ? "Date::Calc::XS version " . Date::Calc::XS::Version() : "Date::Calc::PP version " . Date::Calc::PP::Version() ) . "\n";

timethis($loop, \&test_all);

sub test_all
{
    my($days,$weeks,$check,$doy,$dow,$week);
    my($year,$month,$day,$hour,$min,$sec,$Dy,$Dm,$Dd,$Dh,$Ds,$D_y,$D_m,$D_d,$Dhh,$Dmm,$Dss);
    my($time,$dst,$lang,$date,$century,$string,$oldlang,$max_lang,$lower,$upper);
    $days = Days_in_Year(2009,11);
    $days = Days_in_Month(2009,11);
    $weeks = Weeks_in_Year(2009);
    $check = leap_year(2009);
    $check = check_date(2009,2,29);
    $check = check_time(23,59,59);
    $check = check_business_date(2009,46,4);
    $doy = Day_of_Year(2009,11,12);
    $days = Date_to_Days(2009,11,12);
    $dow = Day_of_Week(2009,11,12);
    $week = Week_Number(2009,11,12);
    ($week,$year) = Week_of_Year(2009,11,12);
    ($year,$month,$day) = Monday_of_Week(46,2009);
    ($year,$month,$day) = Nth_Weekday_of_Month_Year(2009,11,4,2);
    ($year,$week,$dow) = Standard_to_Business(2009,11,12);
    ($year,$month,$day) = Business_to_Standard(2009,46,4);
    $Dd = Delta_Days(1964,1,3, 2009,11,12);
    ($Dd,$Dh,$Dm,$Ds) = Delta_DHMS(1964,1,3, 11,8,1, 2009,11,12, 21,19,45);
    ($Dy,$Dm,$Dd) = Delta_YMD(2008,11,1, 2009,1,31);
    ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = Delta_YMDHMS(2008,11,1, 21,21,21, 2009,1,31, 0,59,13);
    ($Dy,$Dm,$Dd) = N_Delta_YMD(2008,11,1, 2009,1,31);
    ($D_y,$D_m,$D_d, $Dhh,$Dmm,$Dss) = N_Delta_YMDHMS(2008,11,1, 21,21,21, 2009,1,31, 0,59,13);
    ($Dd,$Dh,$Dm,$Ds) = Normalize_DHMS(400,-24,60,-1);
    ($year,$month,$day) = Add_Delta_Days(1964,1,3, 16750);
    ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS(1964,1,3, 11,8,1, 16750,10,17,-1);
    ($year,$month,$day) = Add_Delta_YM(2006,12,31, 1,2);
    ($year,$month,$day) = Add_Delta_YMD(2006,12,31, 1,2,-2);
    ($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS(1964,1,3, 11,8,1, 45,10,9, 10,17,-1);
    ($year,$month,$day) = Add_N_Delta_YMD(2006,12,31, 1,2,-2);
    ($year,$month,$day, $hour,$min,$sec) = Add_N_Delta_YMDHMS(1964,1,3, 11,8,1, 45,10,9, 10,17,-1);
    ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock(0);
    ($year,$month,$day) = Today(1);
    ($hour,$min,$sec) = Now(0);
    ($year,$month,$day, $hour,$min,$sec) = Today_and_Now(1);
    $year = This_Year(0);
    ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Gmtime(1258057836);
    ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Localtime(1258057836);
    $time = Mktime(2009,11,12, 21,31,41);
    ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds, $dst) = Timezone(1258057836);
    $time = Date_to_Time(2009,11,12, 21,31,41);
    ($year,$month,$day, $hour,$min,$sec) = Time_to_Date(1258057836);
    ($year,$month,$day) = Easter_Sunday(2009);
    $month = Decode_Month('Fevereiro',5);
    $dow = Decode_Day_of_Week('Mercredi',2);
    $lang = Decode_Language('Deutsch');
    ($year,$month,$day) = Decode_Date_EU('Nikolaus kommt am 5. Dezember 2009',3);
    ($year,$month,$day) = Decode_Date_US('10/31/09 is Halloween',1);
    $year = Fixed_Window(9);
    $year = Moving_Window(9);
    $date = Compress(2009,11,12);
    ($century,$year,$month,$day) = Uncompress($date);
    $check = check_compressed($date);
    $string = Compressed_to_Text($date,11);
    $string = Date_to_Text(2009,11,12,12);
    $string = Date_to_Text_Long(2009,11,12,13);
    $string = English_Ordinal(123456);
    $string = Calendar(2009,11,0,14);
    $string = Month_to_Text(11,7);
    $string = Day_of_Week_to_Text(4,4);
    $string = Day_of_Week_Abbreviation(4,13);
    $string = Language_to_Text(6);
    $lang = Language();
    $oldlang = Language(9);
    $max_lang = Languages();
    ($year,$month,$day) = Decode_Date_EU2('Nikolaus kommt am 5. Dezember 2009',3);
    ($year,$month,$day) = Decode_Date_US2('10/31/09 is Halloween',1);
    ($year,$month,$day) = Parse_Date('Nov 21 2009',1);
    $lower = ISO_LC('CaMeLbAcK');
    $upper = ISO_UC('cAmElBaCk');
    $string = Date::Calc::Version();
}

__END__

