Path: blob/master/sage/graphs/planarity/platformTime.h
4069 views
#ifndef PLATFORM_TIME1#define PLATFORM_TIME23/*4Planarity-Related Graph Algorithms Project5Copyright (c) 1997-2010, John M. Boyer6All rights reserved. Includes a reference implementation of the following:78* John M. Boyer. "Simplified O(n) Algorithms for Planar Graph Embedding,9Kuratowski Subgraph Isolation, and Related Problems". Ph.D. Dissertation,10University of Victoria, 2001.1112* John M. Boyer and Wendy J. Myrvold. "On the Cutting Edge: Simplified O(n)13Planarity by Edge Addition". Journal of Graph Algorithms and Applications,14Vol. 8, No. 3, pp. 241-273, 2004.1516* John M. Boyer. "A New Method for Efficiently Generating Planar Graph17Visibility Representations". In P. Eades and P. Healy, editors,18Proceedings of the 13th International Conference on Graph Drawing 2005,19Lecture Notes Comput. Sci., Volume 3843, pp. 508-511, Springer-Verlag, 2006.2021Redistribution and use in source and binary forms, with or without modification,22are permitted provided that the following conditions are met:2324* Redistributions of source code must retain the above copyright notice, this25list of conditions and the following disclaimer.2627* Redistributions in binary form must reproduce the above copyright notice, this28list of conditions and the following disclaimer in the documentation and/or29other materials provided with the distribution.3031* Neither the name of the Planarity-Related Graph Algorithms Project nor the names32of its contributors may be used to endorse or promote products derived from this33software without specific prior written permission.3435THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"36AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE37IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE38DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR39ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES40(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;41LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON42ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT43(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS44SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.45*/4647#ifdef WIN324849#include <windows.h>50#include <winbase.h>5152#define platform_time DWORD53#define platform_GetTime(timeVar) (timeVar = GetTickCount())54#define platform_GetDuration(startTime, endTime) ((double) (endTime-startTime) / 1000.0)5556#else5758#include <time.h>5960typedef struct {61clock_t hiresTime;62time_t lowresTime;63} platform_time;6465#define platform_GetTime(timeVar) (timeVar.hiresTime = clock(), timeVar.lowresTime = time(NULL))6667// Many flavors of Unix have CLOCKS_PER_SEC at 1 million, and clock_t as a 4 byte long integer68// which means that the clock() construct has a resolution of only about 2000 seconds69// If we're getting a duration longer than that, then we fall back to the coarser time() measure7071#define platform_GetDuration(startTime, endTime) ( \72( (double) (endTime.lowresTime - startTime.lowresTime) ) > 2000 ? \73( (double) (endTime.lowresTime - startTime.lowresTime) ) : \74( (double) (endTime.hiresTime - startTime.hiresTime)) / CLOCKS_PER_SEC)7576/*77#define platform_time clock_t78#define platform_GetTime() clock()79#define platform_GetDuration(startTime, endTime) (((double) (endTime - startTime)) / CLOCKS_PER_SEC)80*/8182/*83#define platform_time time_t84#define platform_GetTime() time((time_t *)NULL)85#define platform_GetDuration(startTime, endTime) ((double) (endTime - startTime))86*/8788#endif8990#endif919293