80/20 rule: 大部分的时间花在小部分代码上。
性能度量
What are we need in CS
- OS: 分时系统
- Hardware: CPU wait for IO
- measuring program performance
time type:
- wall clock time: the overall time needed to run a particular program or solve a problem.
- user time: executing instructions
- system time: instruction execute in kernel.
cpu time
cpu time = user cpu time + system cpu time
timer in hardware
real time CMOS Clock 实时时钟 RTC
- CMOS RAM: Store time & configuration.
- low powered battery
- for the boot-up process
PIT 可编程间隔定时器,a counter that generates output signal
PIC, 可以用于中断控制。
TSC,时间戳计数器,本质是64bit寄存器,receive CLK signal from RTC。
be accessed using RDTSC——read TSC from register.(纳秒级别)
Windows: (毫秒级别)
QueryPerformanceFrequency
QueryPerformanceCounter
timer in OS
DWORD GetTickCount(void) 毫秒级别,49.7天清零。
-
SYSTEM TIME(year ~ millsec)
- GetLocalTime - 本地时间
- GetSystemTime - UTC
-
FILE TIME(计算时间间隔)
- GetSystemTimeAsFileTime()
timer in c/cpp
clock_t clock_t clock()
time_t time()
时间统计
抽样统计
优点:资源利用少。
缺点:存在随机性,无法完全估计。