Created
August 17, 2021 09:57
-
-
Save conqp/ffce4b5010bb5f40ae27fbbd81eee4c2 to your computer and use it in GitHub Desktop.
Async types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
using std::chrono::duration; | |
using std::chrono::system_clock; | |
#include <future> | |
using std::async; | |
using std::launch; | |
#include <iostream> | |
using std::cout; | |
using std::endl; | |
int main() | |
{ | |
auto start_lazy = system_clock::now(); | |
auto future_lazy = async(launch::deferred, [](){return 42 + 1337;}); | |
cout << future_lazy.get() << endl; | |
cout << "lazy: " << duration<double>(system_clock::now() - start_lazy).count() << endl; | |
auto start_eager = system_clock::now(); | |
auto future_eager = async(launch::async, [](){return 42 + 1337;}); | |
cout << future_eager.get() << endl; | |
cout << "eager: " << duration<double>(system_clock::now() - start_eager).count() << endl; | |
auto start_auto = system_clock::now(); | |
auto future_auto = async([](){return 42 + 1337;}); | |
cout << future_auto.get() << endl; | |
cout << "auto: " << duration<double>(system_clock::now() - start_auto).count() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment