Mutiple-Choice Quiz 4

advertisement
1.
A memory pool is a large block of memory from which small objects are allocated piecemeal by
breaking them off from the pool as required. Under which of the following conditions would such
a scheme result in greatly improved performance?
All objects allocated from the pool are freed at around the same time.
All objects allocated from the pool are of similar sizes.
A garbage collector takes care of freeing memory.
(零散分配集中释放,提高性能)
(a) II only.
(b) III only.
(c) I and II only.
(d) I only.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.3.2 of the course notes.
(a)
-------------------------------------------------------------------------------2.
Which of the following are advantages of using statistical sampling to profile programs?
Exact run times of all functions can be determined.
Code can be instrumented automatically.
The performance impact due to measurement can be minimal.
(a) I, II, and III
(b) II and III only
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 4.1.2 of the course notes.
(b)
-------------------------------------------------------------------------------3.
"Wall time" measures
(wall time 指的是程序的整个执行时间)
(a) the user time plus the system time.
(b) the total duration of a program's execution.
(c) idle time.
(d) the time a program spends waiting for input and output.
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 4.1.1 of the course notes.
(b)
-------------------------------------------------------------------------------4.
Which of the following is likely to offer the best performance improvement for programs that
spend 50% of their time comparing strings?
(用指针指向一个唯一的 string 对象,这样我们比较指针就可以达到比较 string 的目的了)
(a) Be sure to use hardware string-comparison instructions.
(b) Store strings uniquely so that pointer comparison can be used.
(c) Write in-line code for string comparison to eliminate a procedure call.
(d) Call a library function for string comparison.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.2.2 of the course notes.
(c)
1.
A memory pool is a large block of memory from which small objects are allocated piecemeal by
breaking them off from the pool as required. Under which of the following conditions would such
a scheme result in greatly improved performance?
All objects allocated from the pool are freed at around the same time.
All objects allocated from the pool are of similar sizes.
A garbage collector takes care of freeing memory.
(a) II only.
(b) I only.
(c) III only.
(d) I and II only.
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 4.3.2 of the course notes.
(b)
-------------------------------------------------------------------------------2.
Which of the following are useful for observing program performance?
Direct measurement with a stopwatch.
Statistical Sampling.
System Monitors
(a) II and III only
(b) I and III only
(c) I and II only
(d) I, II, and III
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 4.1.2 of the course notes.
(d)
-------------------------------------------------------------------------------3.
"CPU time" measures
(a) wall time
(b) the percentage utilization of the CPU by the system.
(c) the time spent by a program executing program instructions.
(d) the time spent executing system functions.
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 4.1.1 of the course notes.
(c)
-------------------------------------------------------------------------------4.
Amdahl's law, applied to program optimization, says that
(成功的程序优化可能只能产生幅度不断减小的成果)
(a) successive program optimizations tend to produce diminishing returns
(b) each optimization about doubles a program's performance
(c) algorithmic design is more important than code quality for performance
(d) program measurement is a prerequisite to optimization
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
(c)
1.
In C and C++, which of the following functions allocate memory from the heap?
printf()
creating a new Standard Template Library string
cout << "Hello World"
(a) II and III only.
(b) II only.
(c) I only.
(d) I and II only.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.3.1 of the course notes.
(a)
-------------------------------------------------------------------------------2.
"CPU time" measures
(a) wall time
(b) the percentage utilization of the CPU by the system.
(c) the time spent by a program executing program instructions.
(d) the time spent executing system functions.
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 4.1.1 of the course notes.
(c)
--------------------------------------------------------------------------------
3.
Which of the following approaches towards optimizing programs is most advisable?
(优化也要等待调试正确后才行啊)
(a) Optimize the more complex functions first.
(b) "Optimize as you go": make sure every function is optimized before writing the next one.
(c) Optimize after all functions are written and debugged.
(d) Optimize main() first.
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 4.1.1 of the course notes.
(c)
-------------------------------------------------------------------------------4.
Which of the following is likely to offer the best performance improvement for programs that
spend 50% of their time comparing strings?
(a) Call a library function for string comparison.
(b) Be sure to use hardware string-comparison instructions.
(c) Write in-line code for string comparison to eliminate a procedure call.
(d) Store strings uniquely so that pointer comparison can be used.
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 4.2.2 of the course notes.
(d)
3.
Which of the following are advantages of using statistical sampling to profile programs?
Exact run times of all functions can be determined.
Code can be instrumented automatically.
The performance impact due to measurement can be minimal.
(a) I, II, and III
(b) II and III only
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 4.1.2 of the course notes.
(b)
1.
To quickly allocate and free many variables of a commonly used data type, we could
(a) use sizes which are powers of two.
(b) coalesce blocks when they are freed.
(c) keep a linked list of free objects of that type's size.
(d) minimize the size of the data type.
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 4.3.2 of the course notes.
(c)
4.
General wisdom, expressed by the 80/20 rule, says that
(a) algorithmic improvements account for the smallest amount of performance gain
(b) optimization can obtain between 20 and 80 percent improvement
(c) most execution time is spent in a small amount of code
(d) 80% of the execution time is in the user interface, and 20% does the real work
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 4.2.1 of the course notes.
(c)
Download