2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-02-17 00:01:27 +01:00
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Helper functions to measure elapsed time.
|
|
|
|
//
|
|
|
|
// Author: Mikolaj Zalewski (mikolajz@google.com)
|
|
|
|
|
|
|
|
#ifndef WEBP_EXAMPLES_STOPWATCH_H_
|
|
|
|
#define WEBP_EXAMPLES_STOPWATCH_H_
|
|
|
|
|
2012-01-12 13:51:39 +01:00
|
|
|
#if defined _WIN32 && !defined __GNUC__
|
2011-02-17 00:01:27 +01:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
typedef LARGE_INTEGER Stopwatch;
|
|
|
|
|
2011-11-05 03:44:57 +01:00
|
|
|
static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
|
2011-02-17 00:01:27 +01:00
|
|
|
const LARGE_INTEGER old_value = *watch;
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
if (!QueryPerformanceCounter(watch))
|
|
|
|
return 0.0;
|
|
|
|
if (!QueryPerformanceFrequency(&freq))
|
|
|
|
return 0.0;
|
|
|
|
if (freq.QuadPart == 0)
|
|
|
|
return 0.0;
|
|
|
|
return (watch->QuadPart - old_value.QuadPart) / (double)freq.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 07:31:28 +02:00
|
|
|
#else /* !_WIN32 */
|
2011-02-17 00:01:27 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
typedef struct timeval Stopwatch;
|
|
|
|
|
2011-11-05 03:44:57 +01:00
|
|
|
static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
|
2011-02-17 00:01:27 +01:00
|
|
|
const struct timeval old_value = *watch;
|
|
|
|
gettimeofday(watch, NULL);
|
|
|
|
return watch->tv_sec - old_value.tv_sec +
|
|
|
|
(watch->tv_usec - old_value.tv_usec) / 1000000.0;
|
|
|
|
}
|
|
|
|
|
2011-09-07 07:31:28 +02:00
|
|
|
#endif /* _WIN32 */
|
2011-02-17 00:01:27 +01:00
|
|
|
|
2011-09-07 07:31:28 +02:00
|
|
|
#endif /* WEBP_EXAMPLES_STOPWATCH_H_ */
|