benchmark-cpu.pl 1.6 KB

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