2 * Lame time routines source file
4 * Copyright (c) 2000 Mark Taylor
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 /* $Id: lametime.c,v 1.21 2011/05/07 16:05:17 rbrito Exp $ */
25 * name: GetCPUTime ( void )
27 * description: returns CPU time used by the process
29 * output: time in seconds
30 * known bugs: may not work in SMP and RPC
33 * There is some old difficult to read code at the end of this file.
34 * Can someone integrate this into this function (if useful)?
51 #if !defined(CLOCKS_PER_SEC)
52 # warning Your system does not define CLOCKS_PER_SEC, guessing one...
53 # define CLOCKS_PER_SEC 1000000
62 #if defined(_MSC_VER) || defined(__BORLANDC__)
67 return t / (double) CLOCKS_PER_SEC;
72 * name: GetRealTime ( void )
74 * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
76 * output: time in seconds
77 * known bugs: bad precision with time()
80 #if defined(__unix__) || defined(SVR4) || defined(BSD)
82 # include <sys/time.h>
87 { /* conforming: SVr4, BSD 4.3 */
90 if (0 != gettimeofday(&t, NULL))
92 return t.tv_sec + 1.e-6 * t.tv_usec;
95 #elif defined(WIN16) || defined(WIN32)
98 # include <sys/types.h>
99 # include <sys/timeb.h>
103 { /* conforming: Win 95, Win NT */
107 return t.time + 1.e-3 * t.millitm;
114 { /* conforming: SVr4, SVID, POSIX, X/OPEN, BSD 4.3 */ /* BUT NOT GUARANTEED BY ANSI */
124 #if defined(_WIN32) || defined(__CYGWIN__)
132 lame_set_stream_binary_mode(FILE * const fp)
136 #elif defined __BORLANDC__
137 setmode(_fileno(fp), O_BINARY);
138 #elif defined __CYGWIN__
139 setmode(fileno(fp), _O_BINARY);
141 _setmode(_fileno(fp), _O_BINARY);
143 (void) fp; /* doing nothing here, silencing the compiler only. */
149 /* End of lametime.c */