Thread: claculate time of function

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    87

    claculate time of function

    Hi,
    it was time i put my problem with calculating time of function
    claculate time of function
    after progress with the code the forum member
    Elysia give me this instruction to resolve the problem of "0.00" as result
    Code:
    namespace stdc = std::chrono;
    auto start = stdc::high_resolution_clock::now();
    constexpr int LoopCount = 1000000;
    for (int i = 0; i < LoopCount; i++)
    {
        // My code here
    }
    auto end = stdc::high_resolution_clock::now();
    std::cout << stdc::duration_cast<stdc::milliseconds>((end - start) / LoopCount).count() << "\n";
    Now, i am using Visual c++2010 , that don't have "chrono" as std
    is there another alternative of "chrono" and "constexpr"

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why not upgrade Visual C++ to the most recent version?

    Jim

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dreamvig
    Now, i am using Visual c++2010 , that don't have "chrono" as std
    is there another alternative of "chrono" and "constexpr"
    You can use Boost.Chrono for an implementation of chrono; you can use const instead of constexpr here.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    87
    You can use Boost.Chrono
    Yes , i tried to do that adding this include
    Code:
    Code:
    #include <boost/chrono.hpp>
    but it give me fatal error, maybe because i use Ogre3d that have file "boost" too

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dreamvig
    but it give me fatal error, maybe because i use Ogre3d that have file "boost" too
    Maybe, or maybe it is something else.

    Maybe you should just upgrade to a newer IDE and compiler as jimblumberg suggested in post #2. Maybe it will be simpler than trying to figure out a vague "fatal error" and having to deal with maybes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2012
    Posts
    87
    The re is no solution, just to upgrade?
    because i don't have visual 2012 , and i can't update my visual 2010

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dreamvig
    The re is no solution, just to upgrade?
    I already suggested Boost.Chrono as a solution. Fix the "fatal error" and you should be good to go.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Apr 2012
    Posts
    87
    thanks i will see
    my question was , the function in above (using chrono or boost) is it the unique idea of solution to resolve my problem of calculating the time.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, there are other ways. A search of the Web should help.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Visual studio 2015 is the latest and it is free. There's no reason for you to not use it, so why aren't you upgrading?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Apr 2012
    Posts
    87
    Quote Originally Posted by Elysia View Post
    Visual studio 2015 is the latest and it is free. There's no reason for you to not use it, so why aren't you upgrading?
    Thank you for this information,
    i will download it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. claculate time of function
    By dreamvig in forum C++ Programming
    Replies: 27
    Last Post: 06-07-2015, 05:03 AM
  2. Replies: 5
    Last Post: 04-17-2013, 11:32 PM
  3. Replies: 2
    Last Post: 04-17-2013, 12:25 AM
  4. Replies: 2
    Last Post: 01-12-2013, 10:11 AM
  5. Need Help with the time()....Function.
    By Patrick1234 in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 02:14 PM