Deutsch English Français Italiano |
<vjs6ok$323cf$1@paganini.bofh.team> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder8.news.weretis.net!newsfeed.bofh.team!paganini.bofh.team!not-for-mail From: Student Project <student@invalid.invalid> Newsgroups: comp.lang.c++ Subject: Re: g++ v14.1.0 Date: Tue, 17 Dec 2024 15:49:49 +0000 Organization: To protect and to server Message-ID: <vjs6ok$323cf$1@paganini.bofh.team> References: <vjqvhu$305fb$1@paganini.bofh.team> <vjr73j$1j9tc$1@raubtier-asyl.eternal-september.org> Mime-Version: 1.0 Content-Type: text/plain; Content-Transfer-Encoding: 8bit Injection-Date: Tue, 17 Dec 2024 15:52:52 -0000 (UTC) Injection-Info: paganini.bofh.team; logging-data="3214735"; posting-host="oUS9mq3vau9wu0ueCXkkJg.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A"; Content-Language: th X-Notice: Filtered by postfilter v. 0.9.3 Bytes: 2932 Lines: 92 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.