8. (Performance) Consider the following code to generate arrays containing uniform random values: std::vector compute() { //
Question:
8. (Performance)
Consider the following code to generate arrays containing uniform random values:
std::vector
{ // Re-seed uniform generator when requesting a new path uniformGenerator.seed(seeder());
std::vector
std::transform(v.begin(), v.end(), v.begin(), normalGenerator);
return v;
}
Answer the following questions (assuming that nSteps, uniformGenerator and normalGenerator have been defined):
a) Determine how many temporary vectors are created when this function is called from client code. Measure the run-time performance when this function is called one million times.
b) Now consider the use case in which a single vector is created and modified one million times. How would you modify the code of compute()and improve the run-time performance?
c) Generalise the results in parts
a) and
b) to situations in which tuples are used instead of vectors. Consider the code in this chapter to determine the presence of potential performance bottlenecks in the style of discussion in Section 5.8.
Step by Step Answer: