Namensräume
Varianten
Aktionen

std::clock

Aus cppreference.com
< cpp‎ | chrono‎ | c

 
 
 
 
C-style Datum und Uhrzeit Versorgungsunternehmen
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Zeit Manipulation
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
Format Konvertierungen
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
Konstanten
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
Types
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();
Gibt die ungefähre Prozessor-Zeit durch den Prozess seit dem Beginn einer Implementierung definierte Zeit im Zusammenhang mit der Ausführung des Programms verwendet. Zum Suchergebnis Wert Sekunden umwandeln dividieren sie durch CLOCKS_PER_SEC. Weil der Anfang der std::clock Zeit muss nicht mit dem Start des Programms übereinstimmen, ist nur der Unterschied zwischen zwei Werten von verschiedenen Anrufe an std::clock zurückgegeben sinnvoll. Wenn die CPU durch andere Prozesse genutzt wird, können std::clock Zeit vorzustellen langsamer als Wanduhr. Wenn der aktuelle Prozess ist multithreaded und mehr als ein Ausführungskern verfügbar ist, kann std::clock Zeit schneller als Wanduhr Voraus .
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.

Inhaltsverzeichnis

[Bearbeiten] Parameter

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

[Bearbeiten] Rückgabewert

Prozessorzeit von dem Programm verwendet, so weit oder (clock_t)(-1) wenn diese Information nicht verfügbar ist .
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.

[Bearbeiten] Notes

Auf POSIX-kompatiblen Systemen, bietet clock_gettime mit Uhr id CLOCK_PROCESS_CPUTIME_ID bessere Auflösung .
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.
Der Wert von clock() zurückgegeben werden umschlingen auf einigen Implementierungen. Zum Beispiel auf einem Computer mit 32-Bit-std::clock_t, wickelt es nach 2147 Sekunden oder 36 Minuten .
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() ist nicht erforderlich, um Thread-sicher zu sein .
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.

[Bearbeiten] Beispiel

Dieses Beispiel zeigt die Differenz zwischen Takt () Zeit und Echtzeit
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

[Bearbeiten] Siehe auch

wandelt eine time_t Objekt eine textuelle Repräsentation
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.

(Funktion) [edit]
gibt die aktuelle Zeit des Systems als Zeit seit Epoche
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.

(Funktion) [edit]
C documentation for clock