Sujet : Re: g++ v14.1.0
De : student (at) *nospam* invalid.invalid (Student Project)
Groupes : comp.lang.c++Date : 17. Dec 2024, 16:49:49
Autres entêtes
Organisation : To protect and to server
Message-ID : <vjs6ok$323cf$1@paganini.bofh.team>
References : 1 2
On 17/12/2024 06:52, Bonita Montero wrote:
Am 17.12.2024 um 05:39 schrieb Student Project:
Do you guys see any problems in this simple code:
struct Timer
{
std::chrono::time_point<std::chrono::steady_clock> start, end;
std::chrono::duration<float> duration;
>
Timer()
{
start = std::chrono::high_resolution_clock::now();
std::chrono::time_point<std::chrono::high_resolution_clock> start,
end;
}
>
~Timer()
{
end = std::chrono::high_resolution_clock::now();
duration = end - start;
>
float ms = duration.count() * 1000.0f;
std::cout << "Timer took: " << ms << "ms\n";
}
};
>
That's while steady_clock and system_clock are the same with MSVC
(both rely on GetSystemTimeAsFileTime()).
Vielen Dank, Bonita. Es lässt sich jetzt in allen drei Compilern
kompilieren, auf die ich Zugriff habe. Das vollständige, einfache
Programm zum Ausprobieren finden Sie hier:
#include <iostream>
#include <chrono>
#include <thread>
/*
* Compile directives:
For g++:
g++ -std=c++20 -Wall -o obj/main.o -c src/main.cpp
g++ -std=c++20 -Wall -o Program obj/main.o
For clang++:
clang++ -o Program01.exe -Wall main.cpp
For Visual Studio:
cl /EHsc main.cpp
*/
struct Timer
{
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
std::chrono::duration<float> duration;
Timer()
{
start = std::chrono::high_resolution_clock::now();
}
~Timer()
{
end = std::chrono::high_resolution_clock::now();
duration = end - start;
float ms = duration.count() * 1000.0f;
std::cout << "Timer took: " << ms << "ms\n";
}
};
void Function()
{
Timer timer;
for (int i = 0; i < 1000; i++)
{
std::cout << "Hello World!\n";
}
}
int main()
{
Function();
}
Frohe Weihnachten.