VirtualBox

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

Last change on this file since 78253 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.9 KB
Line 
1/* $Id: tstTime-3.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Simple RTTime test.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
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
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/time.h>
32#include <iprt/stream.h>
33#include <iprt/string.h>
34#include <iprt/initterm.h>
35#include <iprt/thread.h>
36#include <iprt/errcore.h>
37
38
39
40int main(int argc, char **argv)
41{
42 RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
43
44 if (argc <= 1)
45 {
46 RTPrintf("tstTime-3: usage: tstTime-3 <seconds> [seconds2 [..]]\n");
47 return 1;
48 }
49
50 RTPrintf("tstTime-3: Testing difference between RTTimeNanoTS() and RTTimeSystemNanoTS()...\n");
51
52 for (int i = 1; i < argc; i++)
53 {
54 uint64_t cSeconds = 0;
55 int rc = RTStrToUInt64Ex(argv[i], NULL, 0, &cSeconds);
56 if (RT_FAILURE(rc))
57 {
58 RTPrintf("tstTime-3: Invalid argument %d: %s\n", i, argv[i]);
59 return 1;
60 }
61 RTPrintf("tstTime-3: %d - %RU64 seconds period...\n", i, cSeconds);
62
63 RTTimeNanoTS(); RTTimeSystemNanoTS(); RTThreadSleep(1);
64 uint64_t u64RTStartTS = RTTimeNanoTS();
65 uint64_t u64OSStartTS = RTTimeSystemNanoTS();
66
67 RTThreadSleep(cSeconds * 1000);
68
69 uint64_t u64RTElapsedTS = RTTimeNanoTS();
70 uint64_t u64OSElapsedTS = RTTimeSystemNanoTS();
71 u64RTElapsedTS -= u64RTStartTS;
72 u64OSElapsedTS -= u64OSStartTS;
73
74 RTPrintf("tstTime-3: %d - RT: %16RU64 ns\n", i, u64RTElapsedTS);
75 RTPrintf("tstTime-3: %d - OS: %16RU64 ns\n", i, u64OSElapsedTS);
76 RTPrintf("tstTime-3: %d - diff: %16RI64 ns\n", i, u64RTElapsedTS - u64OSElapsedTS);
77 }
78
79 return 0;
80}
81
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