Question
In C++ Task The need arises for one to perform benchmarking of code (i.e., time how long something takes to execute). Such is useful enough
In C++
Task
The need arises for one to perform "benchmarking" of code (i.e., time how long something takes to execute). Such is useful enough to place the code to do such inside a function (template) so it can be easily used again later.
main()
The program's main() function has only one function call in it to the benchmark() function you will write later in this assignment. The benchmark() function has a single argument: a lambda function (no arguments, void return) whose body is:
int count = 0; for (double d; cin >> d; ++count) ; cout << count << " double values were read in. ";
The benchmark() Function Template
Start by writing the function prototype followed by the opening {, i.e.,
templatevoid benchmark(Func f) {
Now you must:
- Record the start time, t0, by calling std::chrono::steady_clock::now().
- Call the function that f refers to.
- Record the stop time, t1, by calling std::chrono::steady_clock::now().
- Determine the amount of time (as a double) in seconds that elapsed by calling std::chrono::duration
- Output "benchmark() took
- Close the function definition. (Obviously!)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started