【系统级编程】优化

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()

时间统计

抽样统计

优点:资源利用少。
缺点:存在随机性,无法完全估计。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值