File: TestTimer.hpp

package info (click to toggle)
kokkos 5.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,140 kB
  • sloc: cpp: 225,293; sh: 1,250; python: 78; makefile: 16; fortran: 4; ansic: 2
file content (43 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project

#include <gtest/gtest.h>

#include <Kokkos_Timer.hpp>

#include <thread>
#include <type_traits>
#include <utility>

namespace {

TEST(TEST_CATEGORY, timer) {
  using namespace std::chrono_literals;

  Kokkos::Timer t;
  std::this_thread::sleep_for(5ms);
  auto elapsed = t.seconds();
  EXPECT_GE(elapsed, .005);
  EXPECT_LT(elapsed, 1.);

  std::this_thread::sleep_for(10ms);
  auto elapsed2 = std::as_const(t).seconds();
  EXPECT_GE(elapsed2, .015);
  EXPECT_GT(elapsed2, elapsed);

  t.reset();
  std::this_thread::sleep_for(5ms);
  auto elapsed3 = t.seconds();
  EXPECT_GE(elapsed3, .005);
  // Using the line below turned out to be problematic since there is no
  // guaranteed upper bound for the time std::this_thread::sleep_for is
  // blocking for.
  // EXPECT_LT(elapsed3, elapsed2);
}

static_assert(!std::is_copy_constructible_v<Kokkos::Timer>);
static_assert(!std::is_move_constructible_v<Kokkos::Timer>);
static_assert(!std::is_copy_assignable_v<Kokkos::Timer>);
static_assert(!std::is_move_assignable_v<Kokkos::Timer>);

}  // namespace