VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstTime-3.cpp@ 3125

Last change on this file since 3125 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: tstTime-3.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime Testcase - Simple RTTime test.
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 * 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#ifdef __WIN__
26# include <Windows.h>
27
28#elif defined __L4__
29
30#else /* posix */
31# include <sys/time.h>
32#endif
33
34#include <iprt/time.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/runtime.h>
38#include <iprt/thread.h>
39#include <iprt/err.h>
40
41
42DECLINLINE(uint64_t) OSNanoTS(void)
43{
44#ifdef __WIN__
45 uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */
46 GetSystemTimeAsFileTime((LPFILETIME)&u64);
47 return u64 * 100;
48
49#elif defined __L4__
50 /** @todo fix a different timesource on l4. */
51 return RTTimeNanoTS();
52
53#else /* posix */
54
55 struct timeval tv;
56 gettimeofday(&tv, NULL);
57 return (uint64_t)tv.tv_sec * (uint64_t)(1000 * 1000 * 1000)
58 + (uint64_t)(tv.tv_usec * 1000);
59#endif
60}
61
62
63
64int main(int argc, char **argv)
65{
66 RTR3Init();
67
68 if (argc <= 1)
69 {
70 RTPrintf("tstTime-3: usage: tstTime-3 <seconds> [seconds2 [..]]\n");
71 return 1;
72 }
73
74 RTPrintf("tstTime-3: Testing difference between RTTimeNanoTS() and OS time...\n");
75
76 for (int i = 1; i < argc; i++)
77 {
78 uint64_t cSeconds = 0;
79 int rc = RTStrToUInt64Ex(argv[i], NULL, 0, &cSeconds);
80 if (RT_FAILURE(rc))
81 {
82 RTPrintf("tstTime-3: Invalid argument %d: %s\n", i, argv[i]);
83 return 1;
84 }
85 RTPrintf("tstTime-3: %d - %RU64 seconds period...\n", i, cSeconds);
86
87 RTTimeNanoTS(); OSNanoTS(); RTThreadSleep(1);
88 uint64_t u64RTStartTS = RTTimeNanoTS();
89 uint64_t u64OSStartTS = OSNanoTS();
90
91 RTThreadSleep(cSeconds * 1000);
92
93 uint64_t u64RTElapsedTS = RTTimeNanoTS();
94 uint64_t u64OSElapsedTS = OSNanoTS();
95 u64RTElapsedTS -= u64RTStartTS;
96 u64OSElapsedTS -= u64OSStartTS;
97
98 RTPrintf("tstTime-3: %d - RT: %16RU64 ns\n", i, u64RTElapsedTS);
99 RTPrintf("tstTime-3: %d - OS: %16RU64 ns\n", i, u64OSElapsedTS);
100 RTPrintf("tstTime-3: %d - diff: %16RI64 ns\n", i, u64RTElapsedTS - u64OSElapsedTS);
101 }
102
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