|
Packit |
9c6abc |
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Use of this source code is governed by a BSD-style license
|
|
Packit |
9c6abc |
// that can be found in the COPYING file in the root of the source
|
|
Packit |
9c6abc |
// tree. An additional intellectual property rights grant can be found
|
|
Packit |
9c6abc |
// in the file PATENTS. All contributing project authors may
|
|
Packit |
9c6abc |
// be found in the AUTHORS file in the root of the source tree.
|
|
Packit |
9c6abc |
// -----------------------------------------------------------------------------
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Helper functions to measure elapsed time.
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Author: Mikolaj Zalewski (mikolajz@google.com)
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#ifndef WEBP_EXAMPLES_STOPWATCH_H_
|
|
Packit |
9c6abc |
#define WEBP_EXAMPLES_STOPWATCH_H_
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#include "webp/types.h"
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#if defined _WIN32 && !defined __GNUC__
|
|
Packit |
9c6abc |
#include <windows.h>
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
typedef LARGE_INTEGER Stopwatch;
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
static WEBP_INLINE void StopwatchReset(Stopwatch* watch) {
|
|
Packit |
9c6abc |
QueryPerformanceCounter(watch);
|
|
Packit |
9c6abc |
}
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
|
|
Packit |
9c6abc |
const LARGE_INTEGER old_value = *watch;
|
|
Packit |
9c6abc |
LARGE_INTEGER freq;
|
|
Packit |
9c6abc |
if (!QueryPerformanceCounter(watch))
|
|
Packit |
9c6abc |
return 0.0;
|
|
Packit |
9c6abc |
if (!QueryPerformanceFrequency(&freq))
|
|
Packit |
9c6abc |
return 0.0;
|
|
Packit |
9c6abc |
if (freq.QuadPart == 0)
|
|
Packit |
9c6abc |
return 0.0;
|
|
Packit |
9c6abc |
return (watch->QuadPart - old_value.QuadPart) / (double)freq.QuadPart;
|
|
Packit |
9c6abc |
}
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#else /* !_WIN32 */
|
|
Packit |
9c6abc |
#include <string.h> // memcpy
|
|
Packit |
9c6abc |
#include <sys/time.h>
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
typedef struct timeval Stopwatch;
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
static WEBP_INLINE void StopwatchReset(Stopwatch* watch) {
|
|
Packit |
9c6abc |
gettimeofday(watch, NULL);
|
|
Packit |
9c6abc |
}
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
|
|
Packit |
9c6abc |
struct timeval old_value;
|
|
Packit |
9c6abc |
double delta_sec, delta_usec;
|
|
Packit |
9c6abc |
memcpy(&old_value, watch, sizeof(old_value));
|
|
Packit |
9c6abc |
gettimeofday(watch, NULL);
|
|
Packit |
9c6abc |
delta_sec = (double)watch->tv_sec - old_value.tv_sec;
|
|
Packit |
9c6abc |
delta_usec = (double)watch->tv_usec - old_value.tv_usec;
|
|
Packit |
9c6abc |
return delta_sec + delta_usec / 1000000.0;
|
|
Packit |
9c6abc |
}
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#endif /* _WIN32 */
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#endif /* WEBP_EXAMPLES_STOPWATCH_H_ */
|