Bug 462294 - Add "View Video" to context menu for <video> elements. r=gavin, ui...
[wine-gecko.git] / nsprpub / pr / tests / time.c
blobb8e7d61afcbf138920e60d166cbef8fafd788b92
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * Program to test different ways to get the time; right now it is tuned
40 * only for solaris.
41 * solaris results (100000 iterations):
42 * time to get time with time(): 4.63 usec avg, 463 msec total
43 * time to get time with gethrtime(): 2.17 usec avg, 217 msec total
44 * time to get time with gettimeofday(): 1.25 usec avg, 125 msec total
48 /***********************************************************************
49 ** Includes
50 ***********************************************************************/
51 /* Used to get the command line option */
52 #include "plgetopt.h"
54 #include "nspr.h"
55 #include "prpriv.h"
56 #include "prinrval.h"
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
61 #include <sys/time.h>
63 #define DEFAULT_COUNT 100000
64 PRInt32 count;
66 time_t itime;
67 hrtime_t ihrtime;
69 void
70 ftime_init()
72 itime = time(NULL);
73 ihrtime = gethrtime();
76 time_t
77 ftime()
79 hrtime_t now = gethrtime();
81 return itime + ((now - ihrtime) / 1000000000ll);
84 static void timeTime(void)
86 PRInt32 index = count;
87 time_t rv;
89 for (;index--;)
90 rv = time(NULL);
93 static void timeGethrtime(void)
95 PRInt32 index = count;
96 time_t rv;
98 for (;index--;)
99 rv = ftime();
102 static void timeGettimeofday(void)
104 PRInt32 index = count;
105 time_t rv;
106 struct timeval tp;
108 for (;index--;)
109 rv = gettimeofday(&tp, NULL);
112 static void timePRTime32(void)
114 PRInt32 index = count;
115 PRInt32 rv32;
116 PRTime q;
117 PRTime rv;
119 LL_I2L(q, 1000000);
121 for (;index--;) {
122 rv = PR_Now();
123 LL_DIV(rv, rv, q);
124 LL_L2I(rv32, rv);
128 static void timePRTime64(void)
130 PRInt32 index = count;
131 PRTime rv;
133 for (;index--;)
134 rv = PR_Now();
137 /************************************************************************/
139 static void Measure(void (*func)(void), const char *msg)
141 PRIntervalTime start, stop;
142 double d;
143 PRInt32 tot;
145 start = PR_IntervalNow();
146 (*func)();
147 stop = PR_IntervalNow();
149 d = (double)PR_IntervalToMicroseconds(stop - start);
150 tot = PR_IntervalToMilliseconds(stop-start);
152 if (debug_mode) printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
155 void main(int argc, char **argv)
157 /* The command line argument: -d is used to determine if the test is being run
158 in debug mode. The regress tool requires only one line output:PASS or FAIL.
159 All of the printfs associated with this test has been handled with a if (debug_mode)
160 test.
161 Usage: test_name -d
163 PLOptStatus os;
164 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
165 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
167 if (PL_OPT_BAD == os) continue;
168 switch (opt->option)
170 case 'd': /* debug mode */
171 debug_mode = 1;
172 break;
173 default:
174 break;
177 PL_DestroyOptState(opt);
179 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
180 PR_STDIO_INIT();
182 if (argc > 1) {
183 count = atoi(argv[1]);
184 } else {
185 count = DEFAULT_COUNT;
188 ftime_init();
190 Measure(timeTime, "time to get time with time()");
191 Measure(timeGethrtime, "time to get time with gethrtime()");
192 Measure(timeGettimeofday, "time to get time with gettimeofday()");
193 Measure(timePRTime32, "time to get time with PR_Time() (32bit)");
194 Measure(timePRTime64, "time to get time with PR_Time() (64bit)");
196 PR_Cleanup();
197 return 0;