Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LAGraph/src/test/test_WallClockTime.c: test LAGraph_WallClockTime 3 : //------------------------------------------------------------------------------ 4 : 5 : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved. 6 : // SPDX-License-Identifier: BSD-2-Clause 7 : // 8 : // For additional details (including references to third party source code and 9 : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See 10 : // Contributors.txt for a full list of contributors. Created, in part, with 11 : // funding and support from the U.S. Government (see Acknowledgments.txt file). 12 : // DM22-0790 13 : 14 : // Contributed by Timothy A. Davis, Texas A&M University 15 : 16 : //------------------------------------------------------------------------------ 17 : 18 : #include "LAGraph_test.h" 19 : 20 : //------------------------------------------------------------------------------ 21 : // global variables 22 : //------------------------------------------------------------------------------ 23 : 24 : double t ; 25 : char msg [LAGRAPH_MSG_LEN] ; 26 : 27 : //------------------------------------------------------------------------------ 28 : // test_WallClockTime: test LAGraph_WallClockTime 29 : //------------------------------------------------------------------------------ 30 : 31 1 : void test_WallClockTime (void) 32 : { 33 : 34 1 : OK (LAGraph_Init (msg)) ; 35 : 36 : // start the timer 37 1 : double t = LAGraph_WallClockTime ( ) ; 38 : 39 : // do some useless work 40 1 : double x = msg [0] ; 41 10001 : for (int64_t k = 0 ; k < 10000 ; k++) 42 : { 43 100010000 : for (int64_t i = 0 ; i < 10000 ; i++) 44 : { 45 100000000 : x = x + 1 ; 46 100000000 : if (x > 100) x = x/2 ; 47 : } 48 : } 49 : 50 : // stop the timer 51 1 : t = LAGraph_WallClockTime ( ) - t ; 52 : 53 : // print the result so the compiler doesn't remove the loops above 54 1 : printf ("\nresult: %g, time: %g sec\n", x, t) ; 55 : 56 1 : OK (LAGraph_Finalize (msg)) ; 57 1 : } 58 : 59 : //----------------------------------------------------------------------------- 60 : // TEST_LIST: the list of tasks for this entire test 61 : //----------------------------------------------------------------------------- 62 : 63 : TEST_LIST = 64 : { 65 : { "WallClockTime", test_WallClockTime }, 66 : // no brutal test needed 67 : { NULL, NULL } 68 : } ;