forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime-intrinsic.cpp
32 lines (26 loc) · 1.01 KB
/
time-intrinsic.cpp
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
//===-- runtime/time-intrinsic.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// Implements time-related intrinsic subroutines.
#include "time-intrinsic.h"
#include <ctime>
namespace Fortran::runtime {
extern "C" {
// CPU_TIME (Fortran 2018 16.9.57)
double RTNAME(CpuTime)() {
// This is part of the c++ standard, so it should at least exist everywhere.
// It probably does not have the best resolution, so we prefer other
// platform-specific alternatives if they exist.
std::clock_t timestamp{std::clock()};
if (timestamp != std::clock_t{-1}) {
return static_cast<double>(timestamp) / CLOCKS_PER_SEC;
}
// Return some negative value to represent failure.
return -1.0;
}
} // extern "C"
} // namespace Fortran::runtime