File: benchmark-cpu.pl

package info (click to toggle)
mpg123 1.33.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,428 kB
  • sloc: ansic: 55,525; asm: 17,309; sh: 4,795; makefile: 156; perl: 153; python: 45
file content (64 lines) | stat: -rwxr-xr-x 1,591 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
#
# benchmark-cpu.pl: benchmark CPU optimizations of mpg123
#
# initially written by Nicholas J Humfrey <njh@aelius.com>, placed in the public domain
#

use strict;
#use Time::HiRes qw/time/;

my $MPG123_CMD = shift @ARGV;
my @TEST_FILES = @ARGV;

die "Please specify full path to mpg123 >= 1.7.0 and a test MP3 file to decode" if (scalar(@ARGV) < 1);
die "mpg123 command does not exist" unless (-e $MPG123_CMD);
die "mpg123 command is not executable" unless (-x $MPG123_CMD);
for(@TEST_FILES)
{
	die "test MP3 file does not exist" unless (-e $_);
}

# Force unbuffed output on STDOUT
#$|=1; # why?

# Check the CPUs available
my $cpulist = `$MPG123_CMD --test-cpu`;
chomp( $cpulist );
die "Failed to get list of available CPU optimizations" unless ($cpulist =~ s/^Supported decoders: //);

my @cpus = split( / /, $cpulist );
my @encs = qw(s16 f32);

printf STDERR ("Found %d CPU optimizations to test...\n\n", scalar(@cpus) );

print "#mpg123 benchmark (user CPU time in seconds for decoding)\n";
print "#decoder";
for(@encs){ print "	t_$_/s"; }
print "\n";

my $allret = 0;

foreach my $cpu (@cpus)
{
	print "$cpu";
	foreach my $e (@encs)
	{
		# using user CPU time
		my @start_time  = times();
		my $ret = system($MPG123_CMD, '-q', '--cpu', $cpu, '-e', $e, '-t', @TEST_FILES );
		my @end_time = times();
		my $runtime = $end_time[2] - $start_time[2];
		if($ret)
		{
			print STDERR "Execution of $MPG123_CMD failed with code $ret!\n";
			$runtime = 0;
			$allret = 1;
		}
		# third entry is child user time
		printf("	%4.2f", $runtime);
	}
	print("\n");
}

exit($allret);