名前空間
変種
操作

std::clock

提供: cppreference.com
< cpp‎ | chrono‎ | c

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
 
C形式の日付と時刻のユーティリティ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
時間操作
Original:
Time manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
difftime
time
clock
フォーマット変換
Original:
Format conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
asctime
ctime
strftime
wcsftime
gmtime
localtime
mktime
定数
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CLOCKS_PER_SEC
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tm
time_t
clock_t
 
Defined in header <ctime>
std::clock_t clock();
プログラムの実行に関連する実装定義の時代の始まり以来、プロセスで使用されるおおよそのプロセッサ時間を返します。秒に結果の値を変換するにはCLOCKS_PER_SECで割ります。 std::clock時代の始まりは、プログラムの開始と一致する必要がないため、std::clockに別の呼び出しによって返された二つの値の間の唯一の違いは意味があります。 CPUが他のプロセスによって共有されている場合、std::clock時間は壁時計より遅く進むことができる。現在のプロセスがマルチスレッド化されており、複数の実行コアが使用可能な場合は、std::clock時間は速く壁時計よりも前進することが.
Original:
Returns the approximate processor time used by the process since the beginning of an implementation-defined era related to the program's execution. To convert result value to seconds divide it by CLOCKS_PER_SEC. Because the beginning of the std::clock era does not have to coincide with the start of the program, only the difference between two values returned by different calls to std::clock is meaningful. If the CPU is shared by other processes, std::clock time may advance slower than wall clock. If the current process is multithreaded and more than one execution core is available, std::clock time may advance faster than wall clock.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

(なし)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

その情報が利用できない場合、これまで(clock_t)(-1)またはプログラムによって使用されるプロセッサー時間.
Original:
Processor time used by the program so far or (clock_t)(-1) if that information is unavailable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

POSIX準拠のシステムでは、システム時計イドCLOCK_PROCESS_CPUTIME_IDとclock_gettimeは良好な分解能を提供しています.
Original:
On POSIX-compatible systems, clock_gettime with clock id CLOCK_PROCESS_CPUTIME_ID offers better resolution.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clock()によって返される値は、いくつかの実装で折り返すことがあります。たとえば、32ビットstd::clock_tを積んだマシンで、それは2147秒または36分後にラップ.
Original:
The value returned by clock() may wrap around on some implementations. For example, on a machine with 32-bit std::clock_t, it wraps after 2147 seconds or 36 minutes.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clock()は、スレッドセーフである必要はありません.
Original:
clock() is not required to be thread-safe.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

この例では、クロック()時間と実際の時間との差を示しています
Original:
This example demonstrates the difference between clock() time and real time
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <chrono>
#include <ctime>
#include <thread>
 
// the function f() does some time-consuming work
void f()
{
    volatile double d;
    for(int n=0; n<10000; ++n)
       for(int m=0; m<10000; ++m)
           d += d*n*m;
}
 
int main()
{
    std::clock_t c_start = std::clock();
    auto t_start = std::chrono::high_resolution_clock::now();
    std::thread t1(f); 
    std::thread t2(f); // f() is called on two threads
    t1.join();
    t2.join();
    std::clock_t c_end = std::clock();
    auto t_end = std::chrono::high_resolution_clock::now();
 
    std::cout << "CPU time used: "
              << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC
              << " ms\n";
    std::cout << "Wall clock time passed: "
              << std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start).count()
              << " ms\n";
}

Output:

CPU time used: 1520 ms
Wall clock time passed: 769 ms

[編集] も参照してください

テキスト表現にtime_tオブジェクトを変換します
Original:
converts a time_t object to a textual representation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数) [edit]
エポックからの経過時間など、システムの現在時刻を返します
Original:
returns the current time of the system as time since epoch
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数) [edit]
C documentation for clock