VirtualBox

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

Last change on this file since 4725 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: tstPrfRT.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime testcase - profile some of the important functions.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <iprt/runtime.h>
22#include <iprt/time.h>
23#include <iprt/log.h>
24#include <iprt/stream.h>
25#include <iprt/thread.h>
26#include <iprt/asm.h>
27
28
29void PrintResult(uint64_t u64Ticks, uint64_t u64MaxTicks, uint64_t u64MinTicks, unsigned cTimes, const char *pszOperation)
30{
31 RTPrintf("tstPrfRT: %-32s %5lld / %5lld / %5lld ticks per call (%u calls %lld ticks)\n",
32 pszOperation, u64MinTicks, u64Ticks / (uint64_t)cTimes, u64MaxTicks, cTimes, u64Ticks);
33}
34
35#define ITERATE(preexpr, expr, postexpr, cIterations) \
36 for (i = 0, u64TotalTS = 0, u64MinTS = ~0, u64MaxTS = 0; i < (cIterations); i++) \
37 { \
38 { preexpr } \
39 uint64_t u64StartTS = ASMReadTSC(); \
40 { expr } \
41 uint64_t u64ElapsedTS = ASMReadTSC() - u64StartTS; \
42 { postexpr } \
43 if (u64ElapsedTS > u64MinTS * 32) \
44 { \
45 i--; \
46 continue; \
47 } \
48 if (u64ElapsedTS < u64MinTS) \
49 u64MinTS = u64ElapsedTS; \
50 if (u64ElapsedTS > u64MaxTS) \
51 u64MaxTS = u64ElapsedTS; \
52 u64TotalTS += u64ElapsedTS; \
53 }
54
55int main()
56{
57 uint64_t u64TotalTS;
58 uint64_t u64MinTS;
59 uint64_t u64MaxTS;
60 unsigned i;
61
62 RTR3Init();
63 RTPrintf("tstPrfRT: TESTING...\n");
64
65 /*
66 * RTTimeNanoTS, RTTimeProgramNanoTS, RTTimeMilliTS, and RTTimeProgramMilliTS.
67 */
68 ITERATE(, RTTimeNanoTS();, , 1000000);
69 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNanoTS");
70
71 ITERATE(, RTTimeProgramNanoTS();, , 1000000);
72 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramNanoTS");
73
74 ITERATE(, RTTimeMilliTS();, , 1000000);
75 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeMilliTS");
76
77 ITERATE(, RTTimeProgramMilliTS();, , 1000000);
78 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeProgramMilliTS");
79
80 /*
81 * RTTimeNow
82 */
83 RTTIMESPEC Time;
84 ITERATE(, RTTimeNow(&Time);, , 1000000);
85 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTTimeNow");
86
87 /*
88 * RTLogDefaultInstance()
89 */
90 ITERATE(, RTLogDefaultInstance();, , 1000000);
91 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTLogDefaultInstance");
92
93 /*
94 * RTThreadSelf and RTThreadNativeSelf
95 */
96 ITERATE(, RTThreadSelf();, , 1000000);
97 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadSelf");
98
99 ITERATE(, RTThreadNativeSelf();, , 1000000);
100 PrintResult(u64TotalTS, u64MaxTS, u64MinTS, i, "RTThreadNativeSelf");
101
102 RTPrintf("tstPrtRT: DONE\n");
103 return 0;
104}
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