VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstPrfRT.cpp@ 14534

Last change on this file since 14534 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* $Id: tstPrfRT.cpp 8245 2008-04-21 17:24:28Z vboxsync $ */
2/** @file
3 * IPRT testcase - profile some of the important functions.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <iprt/runtime.h>
35#include <iprt/time.h>
36#include <iprt/log.h>
37#include <iprt/stream.h>
38#include <iprt/thread.h>
39#include <iprt/asm.h>
40
41
42void PrintResult(uint64_t u64Ticks, uint64_t u64MaxTicks, uint64_t u64MinTicks, unsigned cTimes, const char *pszOperation)
43{
44 RTPrintf("tstPrfRT: %-32s %5lld / %5lld / %5lld ticks per call (%u calls %lld ticks)\n",
45 pszOperation, u64MinTicks, u64Ticks / (uint64_t)cTimes, u64MaxTicks, cTimes, u64Ticks);
46}
47
48#define ITERATE(preexpr, expr, postexpr, cIterations) \
49 for (i = 0, u64TotalTS = 0, u64MinTS = ~0, u64MaxTS = 0; i < (cIterations); i++) \
50 { \
51 { preexpr } \
52 uint64_t u64StartTS = ASMReadTSC(); \
53 { expr } \
54 uint64_t u64ElapsedTS = ASMReadTSC() - u64StartTS; \
55 { postexpr } \
56 if (u64ElapsedTS > u64MinTS * 32) \
57 { \
58 i--; \
59 continue; \
60 } \
61 if (u64ElapsedTS < u64MinTS) \
62 u64MinTS = u64ElapsedTS; \
63 if (u64ElapsedTS > u64MaxTS) \
64 u64MaxTS = u64ElapsedTS; \
65 u64TotalTS += u64ElapsedTS; \
66 }
67
68int main()
69{
70 uint64_t u64TotalTS;
71 uint64_t u64MinTS;
72 uint64_t u64MaxTS;
73 unsigned i;
74
75 RTR3Init();
76 RTPrintf("tstPrfRT: TESTING...\n");
77
78 /*
79 * RTTimeNanoTS, RTTimeProgramNanoTS, RTTimeMilliTS, and RTTimeProgramMilliTS.
80 */
81 ITERATE(, RTTimeNanoTS();, , 1000000);
82 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNanoTS");
83
84 ITERATE(, RTTimeProgramNanoTS();, , 1000000);
85 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramNanoTS");
86
87 ITERATE(, RTTimeMilliTS();, , 1000000);
88 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeMilliTS");
89
90 ITERATE(, RTTimeProgramMilliTS();, , 1000000);
91 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramMilliTS");
92
93 /*
94 * RTTimeNow
95 */
96 RTTIMESPEC Time;
97 ITERATE(, RTTimeNow(&Time);, , 1000000);
98 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNow");
99
100 /*
101 * RTLogDefaultInstance()
102 */
103 ITERATE(, RTLogDefaultInstance();, , 1000000);
104 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTLogDefaultInstance");
105
106 /*
107 * RTThreadSelf and RTThreadNativeSelf
108 */
109 ITERATE(, RTThreadSelf();, , 1000000);
110 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadSelf");
111
112 ITERATE(, RTThreadNativeSelf();, , 1000000);
113 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadNativeSelf");
114
115 RTPrintf("tstPrtRT: DONE\n");
116 return 0;
117}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette