| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# benchmark-cpu.pl: benchmark CPU optimizations of mpg123 |
| 4 |
# |
| 5 |
# initially written by Nicholas J Humfrey <[email protected]>, placed in the public domain |
| 6 |
# |
| 7 |
|
| 8 |
use strict; |
| 9 |
#use Time::HiRes qw/time/; |
| 10 |
|
| 11 |
my $MPG123_CMD = shift @ARGV; |
| 12 |
my @TEST_FILES = @ARGV; |
| 13 |
|
| 14 |
die "Please specify full path to mpg123 >= 1.7.0 and a test MP3 file to decode" if (scalar(@ARGV) < 1); |
| 15 |
die "mpg123 command does not exist" unless (-e $MPG123_CMD); |
| 16 |
die "mpg123 command is not executable" unless (-x $MPG123_CMD); |
| 17 |
for(@TEST_FILES) |
| 18 |
{ |
| 19 |
die "test MP3 file does not exist" unless (-e $_); |
| 20 |
} |
| 21 |
|
| 22 |
# Force unbuffed output on STDOUT |
| 23 |
#$|=1; # why? |
| 24 |
|
| 25 |
# Check the CPUs available |
| 26 |
my $cpulist = `$MPG123_CMD --test-cpu`; |
| 27 |
chomp( $cpulist ); |
| 28 |
die "Failed to get list of available CPU optimizations" unless ($cpulist =~ s/^Supported decoders: //); |
| 29 |
|
| 30 |
my @cpus = split( / /, $cpulist ); |
| 31 |
my @encs = qw(s16 f32); |
| 32 |
|
| 33 |
printf STDERR ("Found %d CPU optimizations to test...\n\n", scalar(@cpus) ); |
| 34 |
|
| 35 |
print "#mpg123 benchmark (user CPU time in seconds for decoding)\n"; |
| 36 |
print "#decoder"; |
| 37 |
for(@encs){ print " t_$_/s"; } |
| 38 |
print "\n"; |
| 39 |
|
| 40 |
my $allret = 0; |
| 41 |
|
| 42 |
foreach my $cpu (@cpus) |
| 43 |
{ |
| 44 |
print "$cpu"; |
| 45 |
foreach my $e (@encs) |
| 46 |
{ |
| 47 |
# using user CPU time |
| 48 |
my @start_time = times(); |
| 49 |
my $ret = system($MPG123_CMD, '-q', '--cpu', $cpu, '-e', $e, '-t', @TEST_FILES ); |
| 50 |
my @end_time = times(); |
| 51 |
my $runtime = $end_time[2] - $start_time[2]; |
| 52 |
if($ret) |
| 53 |
{ |
| 54 |
print STDERR "Execution of $MPG123_CMD failed with code $ret!\n"; |
| 55 |
$runtime = 0; |
| 56 |
$allret = 1; |
| 57 |
} |
| 58 |
# third entry is child user time |
| 59 |
printf(" %4.2f", $runtime); |
| 60 |
} |
| 61 |
print("\n"); |
| 62 |
} |
| 63 |
|
| 64 |
exit($allret); |