Calculating elapsed time in a C program in milliseconds

后端 未结 5 1211
你的背包
你的背包 2020-11-29 03:36

I want to calculate the time in milliseconds taken by the execution of some part of my program. I\'ve been looking online, but there\'s not much info on this topic. Any of y

5条回答
  •  有刺的猬
    2020-11-29 04:00

    On Windows, you can just do this:

    DWORD dwTickCount = GetTickCount();
    
    // Perform some things.
    
    printf("Code took: %dms\n", GetTickCount() - dwTickCount);
    

    Not the most general/elegant solution, but nice and quick when you need it.

提交回复
热议问题