Mercurial > spc_convert
view demo/benchmark.c @ 0:e38dacceb958
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 05:53:11 -0700 |
parents | |
children |
line wrap: on
line source
1 /* Measures performance of SPC emulator. Takes about 4 seconds.2 NOTE: This assumes that the program is getting all processor time; you might need to3 arrange for this or else the performance will be reported lower than it really is.5 Usage: benchmark [test.spc]6 */8 #include "snes_spc/spc.h"10 #include "demo_util.h" /* error(), load_file() */11 #include <time.h>13 clock_t start_timing( int seconds );15 int main( int argc, char** argv )16 {17 /* Load SPC */18 long spc_size;19 void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size );20 SNES_SPC* snes_spc = spc_new();21 if ( !snes_spc ) error( "Out of memory" );22 spc_load_spc( snes_spc, spc, spc_size );23 free( spc );25 {26 /* Repeatedly fill buffer for 4 seconds */27 int const seconds = 4;28 #define BUF_SIZE 409629 clock_t end = start_timing( seconds );30 int count = 0;31 while ( clock() < end )32 {33 static short buf [BUF_SIZE];34 error( spc_play( snes_spc, BUF_SIZE, buf ) );35 count++;36 }38 /* Report performance based on how many buffer fills were possible */39 {40 double rate = (double) count * BUF_SIZE / (spc_sample_rate * 2 * seconds);41 printf( "Performance: %.3fx real-time, or %.0f%% CPU for normal rate\n",42 rate, 100.0 / rate );43 }44 }46 return 0;47 }49 /* Synchronizes with host clock and returns clock() time that is duration seconds from now */50 clock_t start_timing( int duration )51 {52 clock_t clock_dur = duration * CLOCKS_PER_SEC;53 clock_t time = clock();54 while ( clock() == time ) { }55 if ( clock() - time > clock_dur )56 error( "Insufficient clock() time resolution" );57 return clock() + clock_dur;58 }