Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.,

template  void benchmark(Func f) { 

Now you must:

  1. Record the start time, t0, by calling std::chrono::steady_clock::now().
  2. Call the function that f refers to.
  3. Record the stop time, t1, by calling std::chrono::steady_clock::now().
  4. Determine the amount of time (as a double) in seconds that elapsed by calling std::chrono::duration
  5. Output "benchmark() took
  6. Close the function definition. (Obviously!)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

Students also viewed these Databases questions

Question

Understand why customers are loyal to a particular service firm.

Answered: 1 week ago