计算时间/空间复杂度

wwwwfly 2008-03-25 11:22:52
1、我在linux下可以用<sys/time.h>下的gettimeofday();函数获得程序微秒级的的运行时间,请问在Windows下有没有类似的函数?
2、怎样获取程序运行时的空间占用情况?
...全文
137 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Supper_Jerry 2008-03-27
  • 打赏
  • 举报
回复
开始GetTickCount
程序结束GetTickCount
求差
pptor 2008-03-27
  • 打赏
  • 举报
回复
int time=GetTickCount();
cout<<GetTickCount()-time<<" ms\n";
paidfighting 2008-03-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cinanynames 的回复:]
clock_t start, finish;
start = clock();
//.............
finish=clock();
//finish-start为上述过程消耗的时间
[/Quote]

(finish-start) / CLOCKS_PER_SEC
Kratos 2008-03-26
  • 打赏
  • 举报
回复
clock_t start, finish;
start = clock();
//.............
finish=clock();
//finish-start为上述过程消耗的时间
野男孩 2008-03-26
  • 打赏
  • 举报
回复
用GetProcessMemoryInfo,计算单个进程是用的内存

The GetProcessMemoryInfo function retrieves information about the memory usage of the specified process.


BOOL GetProcessMemoryInfo(
HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb
);

Parameters
Process
[in] Handle to the process. The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights. For more information, see Process Security and Access Rights.
ppsmemCounters
[out] Pointer to the PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX structure that receives information about the memory usage of the process.
cb
[in] Size of the ppsmemCounters structure, in bytes.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Example Code
For an example, see Collecting Memory Usage Information for a Process.

Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Header Declared in Psapi.h.

Library Link to Psapi.lib.

DLL Requires Psapi.dll.


PROCESS_MEMORY_COUNTERS

The PROCESS_MEMORY_COUNTERS structure contains the memory statistics for a process.


typedef struct _PROCESS_MEMORY_COUNTERS { DWORD cb; DWORD PageFaultCount; SIZE_T PeakWorkingSetSize; SIZE_T WorkingSetSize; SIZE_T QuotaPeakPagedPoolUsage; SIZE_T QuotaPagedPoolUsage; SIZE_T QuotaPeakNonPagedPoolUsage; SIZE_T QuotaNonPagedPoolUsage; SIZE_T PagefileUsage; SIZE_T PeakPagefileUsage;
} PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS;
Members
cb
Size of the structure, in bytes.
PageFaultCount
Number of page faults.
PeakWorkingSetSize
Peak working set size, in bytes.
WorkingSetSize
Current working set size, in bytes.
QuotaPeakPagedPoolUsage
Peak paged pool usage, in bytes.
QuotaPagedPoolUsage
Current paged pool usage, in bytes.
QuotaPeakNonPagedPoolUsage
Peak nonpaged pool usage, in bytes.
QuotaNonPagedPoolUsage
Current nonpaged pool usage, in bytes.
PagefileUsage
Current space allocated for the pagefile, in bytes. Those pages may or may not be in memory.
PeakPagefileUsage
Peak space allocated for the pagefile, in bytes.
Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Header Declared in Psapi.h.


Collecting Memory Usage Information For a Process
To determine the efficiency of your application, you may want to examine its memory usage. The following sample code uses the GetProcessMemoryInfo function to obtain information about the memory usage of a process.
abupie 2008-03-25
  • 打赏
  • 举报
回复
1、我在linux下可以用 <sys/time.h>下的gettimeofday();函数获得程序微秒级的的运行时间,请问在Windows下有没有类似的函数?
这个是库函数,都通用。windows下还有其他的函数。

2、怎样获取程序运行时的空间占用情况?
不知道windows应该怎么做。

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧