VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/* $Id: tstPrfRT.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime testcase - profile some of the important functions.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <iprt/runtime.h>
26#include <iprt/time.h>
27#include <iprt/log.h>
28#include <iprt/stream.h>
29#include <iprt/thread.h>
30#include <iprt/asm.h>
31
32
33void PrintResult(uint64_t u64Ticks, uint64_t u64MaxTicks, uint64_t u64MinTicks, unsigned cTimes, const char *pszOperation)
34{
35 RTPrintf("tstPrfRT: %-32s %5lld / %5lld / %5lld ticks per call (%u calls %lld ticks)\n",
36 pszOperation, u64MinTicks, u64Ticks / (uint64_t)cTimes, u64MaxTicks, cTimes, u64Ticks);
37}
38
39#define ITERATE(preexpr, expr, postexpr, cIterations) \
40 for (i = 0, u64TotalTS = 0, u64MinTS = ~0, u64MaxTS = 0; i < (cIterations); i++) \
41 { \
42 { preexpr } \
43 uint64_t u64StartTS = ASMReadTSC(); \
44 { expr } \
45 uint64_t u64ElapsedTS = ASMReadTSC() - u64StartTS; \
46 { postexpr } \
47 if (u64ElapsedTS > u64MinTS * 32) \
48 { \
49 i--; \
50 continue; \
51 } \
52 if (u64ElapsedTS < u64MinTS) \
53 u64MinTS = u64ElapsedTS; \
54 if (u64ElapsedTS > u64MaxTS) \
55 u64MaxTS = u64ElapsedTS; \
56 u64TotalTS += u64ElapsedTS; \
57 }
58
59int main()
60{
61 uint64_t u64TotalTS;
62 uint64_t u64MinTS;
63 uint64_t u64MaxTS;
64 unsigned i;
65
66 RTR3Init();
67 RTPrintf("tstPrfRT: TESTING...\n");
68
69 /*
70 * RTTimeNanoTS, RTTimeProgramNanoTS, RTTimeMilliTS, and RTTimeProgramMilliTS.
71 */
72 ITERATE(, RTTimeNanoTS();, , 1000000);
73 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNanoTS");
74
75 ITERATE(, RTTimeProgramNanoTS();, , 1000000);
76 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramNanoTS");
77
78 ITERATE(, RTTimeMilliTS();, , 1000000);
79 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeMilliTS");
80
81 ITERATE(, RTTimeProgramMilliTS();, , 1000000);
82 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramMilliTS");
83
84 /*
85 * RTTimeNow
86 */
87 RTTIMESPEC Time;
88 ITERATE(, RTTimeNow(&Time);, , 1000000);
89 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNow");
90
91 /*
92 * RTLogDefaultInstance()
93 */
94 ITERATE(, RTLogDefaultInstance();, , 1000000);
95 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTLogDefaultInstance");
96
97 /*
98 * RTThreadSelf and RTThreadNativeSelf
99 */
100 ITERATE(, RTThreadSelf();, , 1000000);
101 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadSelf");
102
103 ITERATE(, RTThreadNativeSelf();, , 1000000);
104 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadNativeSelf");
105
106 RTPrintf("tstPrtRT: DONE\n");
107 return 0;
108}
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