-
Notifications
You must be signed in to change notification settings - Fork 0
CodeTimer_NET
wzs edited this page Aug 27, 2018
·
1 revision
摘抄自 一个简单的性能计数器_赵劼
C# GC类
- CodeTimer.Initialize 方法: 在测试前调用
- 将当前进程及当前线程的优先级设为最高, 以减少减少操作系统在调度上造成的干扰
- 调用一次Time方法进行 "预热", 让JIT将IL编译成本地代码, 让Time方法尽快 "进入状态"
- Time方法: 真正用于性能计数
-
计时函数比较
-
gettimeofday()
是Linux环境下的RDTSC指令计时函数 -
GetCycleCount()
是Win环境下的RDTSC指令计时函数
-
函数 | 类型 | 精度级别 | 时间 |
---|---|---|---|
time | C系统调用 | 低 | <1s |
clcok | C系统调用 | 低 | <10ms |
timeGetTime | Windows API | 中 | <1ms |
QueryPerformanceCounter | Windows API | 高 | <0.1ms |
GetTickCount | Windows API | 中 | <1ms |
RDTSC | 指令 | 高 | <0.1ms |
统计CPU时钟周期时使用P/Invoke访问 QueryThreadCycleTime 函数, 这是Vista和Server 2008中新的函数