#!/usr/bin/perl

# Copyright (C) 2006 Apple Inc.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1.  Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
# 2.  Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
# 3.  Neither the name of Apple Inc. ("Apple") nor the names of
#     its contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# This script takes two files that are lists of timings and compares them.

use warnings;
use strict;
use Getopt::Long;

my $usage = "compare-timing-files [-c|--count results] oldFile newFile";

my $count = 1;
GetOptions("c|count=i" => \$count);

my ($file1, $file2) = @ARGV;
die "$usage\n" unless ($file1 && $file2 && @ARGV == 2);

my ($oldAverage, $oldRange, $oldRangePercent) = parseResults($file1);
my ($newAverage, $newRange, $newRangePercent) = parseResults($file2);

print "\n===== $file1 =====\n";
if ($count == 1) {
    print("fastest run: $oldAverage\n");
} else {
    print("average of fastest $count runs: $oldAverage\n");
    printf("range of fastest $count runs: %.2f%% (%d)\n", $oldRangePercent, $oldRange);
}

print "\n===== $file2 =====\n";
if ($count == 1) {
    print("fastest run: $newAverage\n");
} else {
    print("average of fastest $count runs: $newAverage\n");
    printf("range of fastest $count runs: %.2f%% (%d)\n", $newRangePercent, $newRange);
}

my $gainOrLoss = $newAverage <= $oldAverage ? "GAIN" : "LOSS";
my $difference = abs($newAverage - $oldAverage);
my $differencePercent = $difference / $oldAverage * 100;
printf("\nperformance %s of %.2f%% (%.1f / %.1f)\n", $gainOrLoss, $differencePercent, $difference, $oldAverage);
print "\n";

sub parseResults
{
    my ($file) = @_;
    
    open(FILE, $file) or die "Couldn't open file: $file";
    my @results = <FILE>;
    close(FILE);

    @results = sort(@results);
    my $total = 0;
    for (my $i = 0; $i < $count; $i++) {
        $results[$i] =~ s/\D*//; # cut out non-digits
        $total += $results[$i]; 
    }
    my $average = $total / $count;
    my $range = $results[$count - 1] - $results[0];
    my $rangePercent = $range / $results[$count - 1] * 100;

    return ($average, $range, $rangePercent);
}

