Blame test/tjutil.c

Packit 9c64f8
/*
Packit 9c64f8
 * Copyright (C)2011 D. R. Commander.  All Rights Reserved.
Packit 9c64f8
 *
Packit 9c64f8
 * Redistribution and use in source and binary forms, with or without
Packit 9c64f8
 * modification, are permitted provided that the following conditions are met:
Packit 9c64f8
 *
Packit 9c64f8
 * - Redistributions of source code must retain the above copyright notice,
Packit 9c64f8
 *   this list of conditions and the following disclaimer.
Packit 9c64f8
 * - Redistributions in binary form must reproduce the above copyright notice,
Packit 9c64f8
 *   this list of conditions and the following disclaimer in the documentation
Packit 9c64f8
 *   and/or other materials provided with the distribution.
Packit 9c64f8
 * - Neither the name of the libjpeg-turbo Project nor the names of its
Packit 9c64f8
 *   contributors may be used to endorse or promote products derived from this
Packit 9c64f8
 *   software without specific prior written permission.
Packit 9c64f8
 *
Packit 9c64f8
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
Packit 9c64f8
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 9c64f8
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 9c64f8
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
Packit 9c64f8
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit 9c64f8
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit 9c64f8
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 9c64f8
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit 9c64f8
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit 9c64f8
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit 9c64f8
 * POSSIBILITY OF SUCH DAMAGE.
Packit 9c64f8
 */
Packit 9c64f8
Packit 9c64f8
#ifdef _WIN32
Packit 9c64f8
Packit 9c64f8
#include <windows.h>
Packit 9c64f8
Packit 9c64f8
static double getfreq(void)
Packit 9c64f8
{
Packit 9c64f8
	LARGE_INTEGER freq;
Packit 9c64f8
	if(!QueryPerformanceFrequency(&freq)) return 0.0;
Packit 9c64f8
	return (double)freq.QuadPart;
Packit 9c64f8
}
Packit 9c64f8
Packit 9c64f8
static double f=-1.0;
Packit 9c64f8
Packit 9c64f8
double gettime(void)
Packit 9c64f8
{
Packit 9c64f8
	LARGE_INTEGER t;
Packit 9c64f8
	if(f<0.0) f=getfreq();
Packit 9c64f8
	if(f==0.0) return (double)GetTickCount()/1000.;
Packit 9c64f8
	else
Packit 9c64f8
	{
Packit 9c64f8
		QueryPerformanceCounter(&t);
Packit 9c64f8
		return (double)t.QuadPart/f;
Packit 9c64f8
	}
Packit 9c64f8
}
Packit 9c64f8
Packit 9c64f8
#else
Packit 9c64f8
Packit 9c64f8
#include <stdlib.h>
Packit 9c64f8
#include <sys/time.h>
Packit 9c64f8
Packit 9c64f8
double gettime(void)
Packit 9c64f8
{
Packit 9c64f8
	struct timeval tv;
Packit 9c64f8
	if(gettimeofday(&tv, NULL)<0) return 0.0;
Packit 9c64f8
	else return (double)tv.tv_sec+((double)tv.tv_usec/1000000.);
Packit 9c64f8
}
Packit 9c64f8
Packit 9c64f8
#endif