系统级程序设计笔记(5)

Performance Measurement and Improvement


前言

本篇博客整理了系统级程序设计课程中的lecture6.

相关材料见:SLP-Notes

待更新

  • time prog -n 17
  • A Trigram Game
  • Practical Hints

Measurement and Profiling

Time Scale

1

  • Computers operate on two fundamentally different time scales.

  • At a microscopic level

    To execute instructions at a rate of one or more per clock cycle, where each clock cycle requires only around one nanosecond (abbreviated “ns”)

  • On a macroscopic scale

    processor must respond to external events that occur on time scales measured in milliseconds (abbreviated “ms”).

Process Scheduling and Timer Interrupts

[简答题] interval time

1

Measuring Time by Interval Counting

间隔计数.

  • [简答题] time segment

    • The operating system also uses the timer to recordthe cumulative time used by each process.
    • This information provides a somewhat imprecisemeasure of program execution time.
    • A time segment refers to the period during whichjust one process executes.
  • P15 ???

    time prog -n 17

  • [简答题] time mechanisms

    1

  • Profiling

    1


Hot Spots

Hot Spot

The 80/20 Rule

  • 80% of the CPU time is spent in 20% of the program
  • These places where the computer spends most of its time are also called hot spots,inner loops, and kernels.

Amdahl’s Law

1

  • All programs have hot spots.
  • A little effort can have large payoffs.
  • If only part of a program can be sped up with parallel processing, then thesequential part of the program woulddetermine and limit the possible speed up.
  • Knowing how to optimize is an importantskill. Knowing when to stop optimizing isalso important.

P34 A Trigram Game???


Practical Hints

Some Expensive Operations

  • printf()
    • printf() causes malloc to be called in the usual implementation, adding an unexpected cost
    • String manipulation is expensive, whether it is formatting text as in printf, reading ASCII text andconverting to numbers, or performing stringcomparisons.
    • Modern computers are designed to accessmemory a word at a time. Accessing a character is no faster than accessing a word, and may be slower.
    • String operations usually operate one character ata time, i.e strlen(), has to examine every character,one at a time.
  • malloc()
    • use static or local variables to avoid allocating memory on the heap.
    • keep a list of objects that need to be allocated often => explicit free-list.
    • Then, allocation is just a matter of removing an object from the list, and freeing simply inserts the object on the list.
  • new()

Example

P45-48 ???

Fast Allocation and Free

1