Check Speed on VS2010

Hello,

How can I check the speed of running a code ? I use VS2010
24 hours are gone,has nobody answered ?
Get time at start. Get time at end. Difference between two is how long the code took to run.
Thanks,

Is there any clock that check in unit of nanoseconds,to see if the time needed by an algorithm to work ?
Yes, there is.
Look up the <ctime> library on this site.
Thank you all,solved.
As an aside, if you've got a reasonable C++11 implementation, this example shows how to measure the time a function took.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <chrono>
#include <thread>
void f()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
    auto t1 = std::chrono::high_resolution_clock::now();
    f();
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout << "f() took "
              << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
              << " milliseconds\n";
}
And about delaying,is it in the same library ? I really confused when load of codes run fast and hard to check.

1
2
#include <chrono>
#include <thread> 


I don't have these 2 libraries in VS2010.
Last edited on
Topic archived. No new replies allowed.