Umgang mit Zeiten in C++ [] (Umgang mit Zeiten in C++), Lektion, page 722679
https://www.purl.org/stefan_ram/pub/zeiten_c++ (permalink) is the canonical URI of this page.
Stefan Ram
C++-Kurs

Umgang mit Zeiten in C++

Für Microbenchmarks besser eine Bibliothek verwenden und Fachtexte lesen, aber hier ist ein einfaches Beispiel:

#include <iostream>

#include <ostream>

#include <string>

#include <chrono>

using namespace ::std::literals;

typedef ::std::chrono::high_resolution_clock Clock;

typedef ::std::chrono::duration<double, std::micro> microseconds ;

typedef ::Clock::time_point time_point;

int fib( int const a ){ return a == 0 ? 0 : a == 1 ? 1 : fib( a - 1 )+ fib( a - 2 ); }

void test( int const a )

{ ::time_point start = ::Clock::now();

auto const f = fib( a );

auto const duration = ::std::chrono::duration_cast< microseconds >

( Clock::now() - start ).count();

::std::cout << a << ' ' << f << ' ' << duration << '\n'; }

int main()

{ for( int j = 1; j < 3; ++j )for( int i = 1; i < 12; ++i )test( i ); }

About this page, Impressum  |   Form for messages to the publisher regarding this page  |   "ram@zedat.fu-berlin.de" (without the quotation marks) is the email-address of Stefan Ram.   |   A link to the start page of Stefan Ram appears at the top of this page behind the text "Stefan Ram".)  |   Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram. relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram722679 stefan_ram:722679 Umgang mit Zeiten in C++ Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd722679, slrprddef722679, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Copyright 1998-2014 Stefan Ram, Berlin. All rights reserved. This page is a publication by Stefan Ram.
https://www.purl.org/stefan_ram/pub/zeiten_c++