mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
microbench: add benchmarking code for Darwin
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
This commit is contained in:
committed by
Erik de Castro Lopo
parent
d91eb4ae75
commit
ab300d4b18
@@ -29,6 +29,8 @@
|
|||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@@ -63,6 +65,36 @@ benchmark_function (void (*testfunc) (void), unsigned count)
|
|||||||
return counter_diff (&start, &end) / count ;
|
return counter_diff (&start, &end) / count ;
|
||||||
} /* benchmark_function */
|
} /* benchmark_function */
|
||||||
|
|
||||||
|
#elif defined FLAC__SYS_DARWIN
|
||||||
|
|
||||||
|
#include <mach/mach_time.h>
|
||||||
|
|
||||||
|
static double
|
||||||
|
counter_diff (const uint64_t * start, const uint64_t * end)
|
||||||
|
{
|
||||||
|
mach_timebase_info_data_t t_info;
|
||||||
|
mach_timebase_info(&t_info);
|
||||||
|
uint64_t duration = *end - *start;
|
||||||
|
|
||||||
|
return duration * ((double)t_info.numer/(double)t_info.denom);
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
benchmark_function (void (*testfunc) (void), unsigned count)
|
||||||
|
{
|
||||||
|
uint64_t start, end;
|
||||||
|
unsigned k;
|
||||||
|
|
||||||
|
start = mach_absolute_time();
|
||||||
|
|
||||||
|
for (k = 0 ; k < count ; k++)
|
||||||
|
testfunc();
|
||||||
|
|
||||||
|
end = mach_absolute_time();
|
||||||
|
|
||||||
|
return counter_diff (&start, &end) / count ;
|
||||||
|
} /* benchmark_function */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|||||||
Reference in New Issue
Block a user