benchmark-cpu.pl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. foreach my $cpu (@cpus)
  32. {
  33. print "$cpu";
  34. foreach my $e (@encs)
  35. {
  36. # using user CPU time
  37. my @start_time = times();
  38. system($MPG123_CMD, '-q', '--cpu', $cpu, '-e', $e, '-t', @TEST_FILES );
  39. my @end_time = times();
  40. # third entry is child user time
  41. printf(" %4.2f", $end_time[2] - $start_time[2]);
  42. }
  43. print("\n");
  44. }