Last active
April 22, 2018 05:30
-
-
Save kittinunf/e7b5e000228942f9ba3b67813aca7786 to your computer and use it in GitHub Desktop.
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 <string> | |
#include <chrono> | |
#include <thread> | |
#include <iostream> | |
using namespace std::chrono; | |
auto calculation1(std::string d) { | |
std::this_thread::sleep_for(seconds(5)); | |
return "cal1_" + d; | |
} | |
auto calculation2(std::string d) { | |
std::this_thread::sleep_for(seconds(5)); | |
return "cal2_" + d; | |
} | |
int main() { | |
auto start = system_clock::now(); | |
auto data1 = calculation1("Data"); | |
auto data2 = calculation2("Data"); | |
auto end = system_clock::now(); | |
auto diff = duration_cast<seconds>(end - start).count(); | |
std::cout << "Total Time = " << diff << " Seconds" << std::endl; | |
//Combine The Data | |
auto data = data1 + "::" + data2; | |
//Printing the combined Data | |
std::cout << "Data = " << data << std::endl; | |
return 0; | |
} |
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 <string> | |
#include <chrono> | |
#include <thread> | |
#include <iostream> | |
#include <future> | |
using namespace std::chrono; | |
auto calculation1(std::string d) { | |
std::this_thread::sleep_for(seconds(5)); | |
return "cal1_" + d; | |
} | |
auto calculation2(std::string d) { | |
std::this_thread::sleep_for(seconds(5)); | |
return "cal2_" + d; | |
} | |
int main() { | |
auto start = system_clock::now(); | |
//auto data1 = calculation1("Data"); | |
auto futureData1 = std::async(std::launch::async, calculation1, "Data"); | |
auto data2 = calculation2("Data"); | |
// auto resultData2 = std::async(std::launch::async, calculation2, "Data"); | |
auto end = system_clock::now(); | |
auto diff = duration_cast<seconds>(end - start).count(); | |
std::cout << "Total Time = " << diff << " Seconds" << std::endl; | |
//Combine The Data | |
//auto data = data1 + "::" + data2; | |
auto data = futureData1.get() + "::" + data2; | |
//Printing the combined Data | |
std::cout << "Data = " << data << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment